I would also recommend purchasing online the 'Mountain Directory for Truckers and RVers'. Even though we drove mountain roads constantly because we like to and we enjoy the gorgeous scenery, we always consulted the directory before traveling to those areas. Even though we traveled the same mountain roads often we would refresh ourselves as to what's ahead.
With your 40' motorhome you shouldn't have any problems weaving in and out of the mountains. We also had a 40' motorhome.
Now...to get to Teton Nat'l Park and Yellowstone, if you want to go through Salt Lake City, stay on I-15 to Idaho Falls.
If you plan to stay in West Yellowstone, take Hwy 20 north - no mountain driving. Then when you're finished with Yellowstone you can head south through the park itself into the Tetons.
Staying at Colter Bay RV in Teton Nat'l Park itself is the very best to tour this area. It's a beautiful setting with full hookups. That's the only hookup in the park.
However, if you can do without hookups as we do, other options for inside the Teton park are Colter Bay campground (right next door to the Colter Bay RV) or a little closer to the town of Jackson is Gros Ventre campground inside the park. This is our favorite.
Both of the 'campgrounds' have dump stations with water fill and each has 300 NON-RESERVABLE sites. They rarely fill except perhaps on the 3-day holidays. If you pull in early in the day you'll get a site.
The Jackson town RV parks are very expensive and in our opinion, aren't nice at all.
Depending on where you're going after the Tetons, Hwy 287 or Hwy 191 will take you easily to I-80.
Of course, you can reverse this and stay in the Tetons first. Getting a reservation at Colter Bay RV might be more difficult than the many choices around West Yellowstone so you might work around the Teton availability.
From Idaho Falls you would take Hwy 26 to Alpine, Wyoming and then take 89 north into Jackson and continue on into Teton Nat'l Park. There are 2 large groceries on 89 just south of Jackson - Smith's Plaza on the left and Albertson's (I believe) on the right a little further north. For diesel fuel with easy entrance and being uncrowded there is a station in Alpine. There are stations in Jackson but are very congested. There are also stations in West Yellowstone but filling in Idaho Falls would be cheaper.
Above all, once you're on Hwy 26 from Idaho Falls, don't be tempted to take a shorter route to Jackson on Hwy 22 between Victor and Jackson. That's a steep, curvy section and I wouldn't recommend it. Instead, stay on 26 to Alpine.
If you do the Tetons first and then West Yellowstone, you could exit the area by taking 287 north to Bozeman, Montana and I-90.
Both parks involve a lot of driving so don't stay too far out of the parks.
Have a great trip! Once you start driving some of the good mountain roads, you be a pro and love it.