With two days to spare, I'd allocate one to each of Yosemite and the Grand Canyon. If you possibly can, follow Michael's suggestion of staying within the park for at least one night. In which case I would make the first night either Williams or Flagstaff, and then enter the Canyon through the east entrance, and follow the Colorado river into the canyon. There are numerous viewpoints along this drive. You could explore the Canyon all day (there's much more than a day's worth of sightseeing there), withness the sunset and if you are up to it, the sunrise as well. Then either spend some more time at the Canyon, or leave for the drive to LV, stopping at Hoover Dam along the way.

Same thing with Yosemite, spend one night outside the park, one night in the park and then leave for SF when you have had your fill of that Park. (Hard to get a fill of that magnificent place. lol)

Lifey