Neil,
The data you requested are all in Table 2 of
http://www.transportation.anl.gov/pdfs/TA/635.PDF - "2008 U.S. Petroleum Refinery Inputs and Outputs".
They don't spell out what percentage of the energy content of the output is motor gasoline, but they do mention that 84.6% of the refinery outputs' energy content is distillate fuels, which to my mind is the first seven bolded items under "Refinery and Blender Net Production". So if you add up those seven items' energy content and divide the energy content of 3.1 billion bbl of gasoline into it, and multiply by .846, you'll get gasoline's share of the output.
Multiply that fraction by the 42TWh in from Table 1, and there you go.