From clothing: Remove as much of the peanut butter by scraping off the excess with a dull butter knife or spoon. Using your favorite stain remover, pretreat the stain for about an hour, then wash on the hottest possible setting with color-safe bleach and laundry detergent (preferably one with enzymes like Tide or Arm & Hammer), which are great for breaking up food stains. Allow to air-dry.
If that doesn't work, a combo of one tablespoon dishwashing liquid, one tablespoon white vinegar, and two cups water works well on many food stains. Apply the mixture directly to the stain, then use an old toothbrush or small brush and gently scrub the stain with the mixture before washing and drying in the process listed above.
From carpet: Scrape any excess peanut butter with a dull knife or spoon, then gently sponge the stain with a carpet-cleaning solvent like Resolve. Let soak for five minutes; blot or rub gently with a clean, damp cloth or sponge; and repeat if necessary.