The best way to store peanuts is in an airtight container in the refrigerator or freezer. This will prevent them from becoming exposed to oxygen and humidity, which can speed up the process of rancidification. If you have an unopened bag of peanuts, then they're usually best left in their original packaging.
If you've already opened the bag, then it's best to store them in a glass jar or Tupperware container with a lid. Make sure that the container is completely dry before adding the peanuts, as moisture can cause them to go off more quickly. It's also important to remove as much air as possible from the container before sealing it shut.
When stored in an airtight container in the refrigerator, peanuts will usually stay fresh for 3-4 months. If you keep them in the freezer, then they should last for 9-12 months.
Once opened, roasted peanuts will usually only stay fresh for 1-2 weeks stored in a sealed container in the refrigerator or 2-3 months in the freezer.
