To ensure the best coffee at home, buy whole beans roasted within the past week and grind them just before you brew. It is always best to buy a small amount of coffee at a time. Odd as it may sound, the surest way to obtain recently roasted coffee is to order it by mail, since companies usually ship a day or two after roasting. The best way to store coffee beans, ground or whole, is in an opaque, airtight canister just big enough to hold them, with as little air at the top as possible. Keep the coffee at room temperature and use it within 10 days if possible.
Many people store coffee in the refrigerator or freezer.
The freezer is a better option, though ground coffee can absorb odors even there - and the oils in beans congeal when frozen, possibly affecting the body of brewed coffee.