Oxygen is enemy number one. Oxidation breaks down the oils and aromatic compounds in coffee, which is why pre-ground coffee stales so fast: grinding multiplies the surface area exposed to air. Ground coffee loses much of its magic within days, while whole beans hold on for weeks.
Light is next. Sunlight and even bright kitchen light degrade coffee's delicate compounds, which is one reason good roasters use opaque bags. Heat accelerates every staling reaction, so the cupboard above the stove or next to the dishwasher is the worst storage spot in your kitchen. Finally, moisture: coffee is hygroscopic, meaning it absorbs water and odors from the air around it, and both ruin the flavor.
Protect your beans from air, light, heat, and moisture, and you have handled 95 percent of coffee storage.
Freezing divides opinion, but the research is fairly kind to it. If you buy more than two weeks of coffee, freeze the surplus in an airtight container, portioned so you only thaw what you need. Let it come to room temperature before opening, so condensation forms on the outside of the container rather than on the beans.