How much total heat is contained in the upper layers of the atmosphere?
Mass at 21.9.1998 for Height 140 km -1000 km was $6.16\cdot10^{10} \mathrm{kg}$.
Avg. Temperature; $725 \mathrm{K}$  

Roughly the mass is divided as follows;
$\mathrm{O}$, $\mathrm{O}_2$; $252 \cdot10^9 \mathrm{kg}$, “16” Molecule amount $N = 9.5\cdot10^{35}$,
Heat capacity; $920 \mathrm{J}/(\mathrm{kg} \mathrm{K})$

$\mathrm{N}$, $\mathrm{N}_2$; $364 \cdot10^9 \mathrm{kg}$; “14” Molecule amount $N = 1.56\cdot10^{36}$,
Heat capacity; $1040 \mathrm{J}/(\mathrm{kg}\mathrm{K})$

$\mathrm{He}$; $35.2\cdot10^6 \mathrm{kg}$, “4” Molecule amount $N = 5.3\cdot10^{33}$,
 Heat capacity; $5193 \mathrm{J}/(\mathrm{kg} \mathrm{K})$

$\mathrm{H}$; $1.34\cdot10^6 \mathrm{kg}$, “1” Molecule amount $N = 0.8\cdot10^{33}$,
Heat capacity; $14304 \mathrm{J}/(\mathrm{kg}\mathrm{K})$ 

Total Heat capacity; $61.2\cdot10^{12} \mathrm{J}/\mathrm{K}$ 
Quelle; My own work.

From here you can calculate $725 \mathrm{K} \cdot 61.2 \cdot10^{12} \mathrm{J}/\mathrm{K} =44.4 \cdot10^{15} \mathrm{J}$

Please note that most of the heat is at the lower atmosphere plain because >99% of the mass is there.