You take an average of 5 kilowatt hours to refine gasoline
I question that claim. I've worked through the numbers for California refineries and found that they use a bit less
energy per gallon of gasoline but only a small portion of that energy comes from outside purchased electricity. Most of the energy comes from natural gas, coal, coke, and some of the petroleum itself.
Here are the energy inputs for 2010, all converted to kWh equivalents...
LPG 2,710,629,777
Distillate Fuel Oil 812,426,729
Still Gas 292,044,328,839
Petroleum Coke 146,560,003,581
Marketable Petroleum Coke 1,584,461,115
Catalyst Petroleum Coke 144,975,542,465
Other Petroleum Product 4,165,172,029
Natural Gas 221,589,097,304
Coal 246,483,001
Purchased Electricity 46,227,000,000
Purchased Steam 37,802,168,816