The cheapest way to visit YNP/GTNP is to tent camp. It lets you stay inside the park (which means saving hours of driving) for an average of $25-35/night. And with a camp stove, you can cook your own meals. Camp stoves are okay to fly with IF they are 100% clean (check with your airline, of course), and then you can buy fuel when you arrive. Or you can rent gear from an REI in Salt Lake City.
Non-camping lodging inside the parks is very expensive, and lodging all around the parks tends to run pretty high too. It can work to visit GTNP while staying in Jackson Hole (but Jackson Hole has some pretty tight restrictions on AirBnBs, if I recall...there may be some slightly cheaper hotels). In particular, I think it's a hassle to stay outside Yellowstone and drive into the park every day. Yellowstone is huge and driving is slow, so staying in a nearby town typically means going in and out over the same section of road again and again. Having said that, you could try checking West Yellowstone and Gardiner for possibilities.
If you end up staying in hotels/lodges/cabins and still want to economize on food, you can opt to bring a cooler (and again, maybe a camp stove...or if you can make it work for some meals, an electric hot water kettle) and avoid the overpriced, sub-par national park dining options. Even just packing your own breakfasts/lunches helps save a bit, with the added bonus of giving you a break from lunchtime crowds in certain hubs.
Hope you have a fun trip!