It looks like the retail marijuana outlet closest to the Denver airport is Timberline Herbal Clinic and Wellness Center. That looks to be a ~30 minute drive each way, or more like 90 minutes to 2 hours by mass transit. You might be able to arrange a ride with Supershuttle. But at best you're going to be cutting things close with a 4 1/2 hour layover.
If you can get there and back, as a non-resident you'll be permitted to buy up to 1/8 ounce of marijuana, which can be in either smokeable or edible forms. You'll have to show ID to verify age and place of residence. It looks like that would cost about $70 depending on which variety you choose. Most places will sell smaller quantities too.
Edibles are probably be no problem to consume. Smoking it may be awkward for a quick visit. You can't legally smoke it in public. Anti-smoking rules at bars, etc, apply to any kind of smoking. For a stopover side trip, edibles are probably the only option (unless you have a helpful friend who will invite you over to their place).
As Nate Eldredge noted in a comment, you can't bring it back to the airport with you, so plan on being finished before you return.
Finally: legal marijuana is still something of an experiment in Colorado. So far it's working out very well, but if that were to change, people might decide it wasn't such a good idea. Whatever happens, please don't do anything that might tend to screw things up for everyone else.