This is difficult to answer exactly since the thermodynamics of cellular metabolism are not well understood.
These are spontaneous reactions, so there is certainly a loss of Gibbs' energy $\Delta G < 0$; this energy corresponds to your "energy" term on the product side of the reactions. For the anaerobic case (glycolysis) a balanced reaction formula is
Glucose + 2 ADP + 2 Pi $\rightarrow$ 2 Lactate + 2 ATP + 2 H2O
Details like phosphate (Pi) and water is important here. Now, if we know the free energies $G$ of each substrate and product, we can calculate the $\Delta G$ as the sum of the products' energies minus the sum of the reactants. Unfortunately, this energy $G$ is hard to get at. It depends on a number of things, like the molecule structure, concentration, temperature and the pH and ion strength of the solution. These things are not exactly known, so the answer will be uncertain. This is actually an active area of research, and sophisticated methods have been developed for calculating $G$. One of the best are from a groyp at the Weizmann institute in Israel, and is available at http://equilibrator.weizmann.ac.il
If we assume all concentrations to be 1mM, this method gives $\Delta G = -118.7$ for the glycolytic reaction above. This is the energy lost (mainly as heat) in the reaction. For comparison with energy captures by ATP, we can break up the reaction into two parts and calculate
Glucose $\rightarrow$ 2 Lactate $\quad\quad\quad\quad\quad \Delta G = -206.7$
2 ADP + 2 Pi $\rightarrow$ 2 ATP + 2 H2O $\quad\quad\Delta G = 87.0$
which sums to -118.7, as expected. This tells us the fraction of the Gibb's energy captured as ATP is 87/206.7 = 42%, while 58% is lost as "heat". So glycolysis has an efficiency of 42%. (For comparison, a combustion engine is somewhere at 15--20%.)
The aerobic case is more difficult, because the stoichiometry is not even fixed: the number of ATP molecules actually obtained from 1 molecule of glucose depends on the efficiency of the respiratory chain, on cytosolic NADH oxidation, and otherthings. But let's say we get 30 ATP. Then
Glucose + 30 ADP + 30 Pi + 6 O2 $\rightarrow$ 6 CO2 + 30 ATP + 36 H2O
has $\Delta G = -1608$, which can be broken up into
Glucose + 6 O2 $\rightarrow$ 6 CO2 + 6 H2O $\quad\quad\Delta G = -2913$
30 ADP + 30 Pi$\rightarrow$ 30 ATP + 30 H2O $\quad\quad\Delta G = 1305$
So here 1305/2913 = 45% of the energy is captured. So in this sense, glycolysis and respiration are similar in efficiency. Varying the number of ATP changes this value; try it! Of course, glycolysis can only partially oxidize glucose (into lactate), while respiration achieves complete oxidation to CO2, extracting much more energy.
Again, these values depends heavily on concentrations of metabolites inside cells, which are not well known. Try changing them at the equilibrator web site and note the effects! Unfortunately, many biochemistry textbooks present values of $\Delta G$ assuming reactants at 1M (!) which is completely irrelevant to actual conditions in living cells.