The best way to preserve the flavour of a fresh roasted bag is to store your coffee in an air tight, moisture free environment, away from heat and light. Heat, light, and air will accelerate the development of quinic acids in the beans, which leads to sour tasting coffee. While it's still not going to hurt you to drink this, it will not taste the same as a fresh roasted bag.
I can't speak for every coffee on the market, but at 421 Brew House we have developed an industry leading, standup pouch bag that gives a longer shelf life. We typically see a ~3 month shelf life in our coffee, before the flavour starts to sour and the taste suffers. Our bags are reusable, so you can use them for all your future coffee storage solutions.
What is that funny button-thing on a coffee bag? It's a degassing valve. We use these because when coffee is freshly roasted it will off-gas for 5-7 days. This is just the coffee settling from the chemical changes in the roasting process. If that gas can't leave the bag, it will build up and react with the acids in the coffee, accelerating the breakdown of flavours.