Better beans, stored correctly, simply make better-tasting coffee!
Pre-ground vs whole beans: The beans themselves are the best vessel for protecting the quality of the coffee. Once your coffee beans around ground, they oxidise very rapidly. Grinding right before you brew is best if possible.
How long it lasts: This depends on how your coffee is packaged. A one-way valve foil bag with pinholes (to let gas out but no air in) will allow the coffee a good few weeks before it loses its liveliness and begins to taste flat. If your coffee came in one of those, leave it in there! Do make sure to store in your cupboard, away from light, and at room temperature.
To freeze or not to free: Short answer? Don't freeze, or store it in the fridge. The cell structure of coffee is soft and porous, and likes to absorb aromatics. That’s code for: If you have garlic or onions in your freezer, your coffee beans might take on some of that flavour. Storing in the fridge causes coffee to condensate and pushes oils to the surface, ageing the coffee faster. If you must store your coffee in the freezer, ensure the bag is sealed and unopened. Allow the beans to thaw to room temperature before consuming.
Stale coffee: Waste not, want not. Don't throw out your old coffee - you can use stale beans for a special type of brew: cold brew!
Conclusion: Buy small amounts of fresh-roasted coffee in airtight containers, then store them at room temperature. And drink as much as you can as quickly as you can - coffee waits for no one.
Check out the following article for more info: If You Care About Your Coffee, You Should Know How To Store It