Coffee beans will retain their essential oils and flavor compounds longest if stored in a dry, dark, airtight container. Refrigeration and freezing are therefore not desirable options since they will almost always cause moisture to form on the surface of the beans.
Note that for the first couple weeks after the coffee has been roasted it will naturally release a lot of carbon dioxide, so the airtight container must have some sort of one-way vent valve to let the gas out. Therefore, the pre-sealed coffee bags that are now ubiquitous in stores are ideal since they have a built-in one-way valve. There are also some vacuum container devices specifically designed for storing coffee beans that have a small pump to pump out the air once or twice a day.
Once the beans are roasted, their essential flavor compounds quickly start to degrade. Therefore, do not buy beans unless you know their roasting date. If stored in ideal conditions, the beans should remain in peak condition for two or three months.