It's an interesting discussion, because if you assume access to atmospheric oxygen, gasoline is MUCH more energy dense.
TNT.....: 4 kJ/gram and 7 MJ/liter
Gasoline: 43 kJ/gram and 33 MJ/literThat's a huge assumption that won't always be the case though. A gasoline tank with a small hole in it is a lot safer than a liquid-electrolyte battery with a hole in it.
The previous point is fair though. What is the energy density of gasoline in a stoichiometric mixture with its oxidizer and not already detonated? That's where TNT beats it by a long shot. The mixture with any chance of being stored would be some relatively low pressure gas.
Edit: Or, a fair closed-system comparison to a battery would need to include a liquid oxygen tank or similar so you have the two components stored but can control the delivery...