The drive takes about 5 hours each way. A stop at the dam will add an hour or so. Staying until sunset means exiting the park in the dark, and in heavy traffic. The first 90 minutes will include an extraordinary amount of wildlife on the roads, from critters as small as hares and skunks to as large as elk. Hitting any of them will do more than spoil your day.
In short, a day trip is doable, but if sunset is on your list, I'd strongly advise booking a room at the park for an overnight stay. It will enhance your GCNP experience exponentially. Bonus is that you'll be there for sunrise too. And I'd advise saving the dam for the return trip or do it on another day from LV.