Really? Trolling a coffee thread?
The most common thing I hear is the rule of "2".
2 days for grounds
2 weeks for roasted
2 months for unroasted
Some of the coffee-nati will tell you it's two hours for grounds, but I think that's a bit extreme.
I'd fall under that bolded bit if I was invested in the whole process. Once I have a place with room, my espresso machine and grinder will be brought back out. I'll either get a professional coffee roaster, or I'll go with a specific style of hot-air popcorn popper again (last popper one got left behind or thrown out after moving... I think).
Never grind until ready, and only grind what you will brew basically right then.
Fresh roasted beans at first get a slight bit of air. Well, a lot of air while they cool to room temp, then a little bit of air (like a mason jar with holes in the seal). After roughly 48 hours of degassing, it's usually good to start sealing it up. If you have any storage with one-way valves, permanently storing in this is best - but if not, occasionally opening a sealed mason jar will be enough to let air out, but if that's the only option, the first two or three days should definitely not be fully sealed.
After roasting (not factoring in degassing time), the whole beans are usually good for between 7-14 days (peak). They can be good to consume for much longer, don't forget that. You get into pre-ground, two-pound tub territory if you start waiting too long though, which, imho, removes the entire point of doing it yourself.
You really don't want to let grounds sit, I wouldn't even recommend two hours - I recommend grind and brew: only grind what you will brew right then and there, seal the rest. Excess grounds? Measure correctly to minimize how much you throw away.
That said - there really is not one size fits all answer. Well, for ground coffee, I'd argue it always fits: don't let grounds sit exposed.
For roast beans (and green/unroasted beans - sealed properly I've heard they can last awhile, longer than 2 months at least), peak flavor could be a few days after roast date, a week after roast date, or perhaps 10-12 days after roast date. This also depends on the desired flavor, but more than anything, on the individual beans, the roast level, and of course environment/storage.
If you buy a fresh roast, or roast yourself, I'd sample with fresh grinds and take notes of each day. You might find your preferred flavor from that roast peaks around a certain time.