|MadSci Network: Earth Sciences|
Your assessment of heating in the thermosphere is close but not quite right. The heating in the thermosphere results when solar energy is absorbed by particles (atoms and molecules) in the thermosphere. The absorption of energy by the particles makes them move faster.
As for the stratosphere, the same process works here as well. The main player is ozone. It absorbs incoming ultraviolet light, accomplishing two things. First, it increases its temperature. Second, it protects us from some incoming ultraviolet light (UV) which is harmful to our skin. The reason for the increase in temperatures in the stratosphere with height relates to the wavelength of the incoming solar energy. At higher altitudes in the stratosphere, ozone very efficiently absorbs UV at wavelengths between 200 and 350 nanometers. At lower altitudes in the stratosphere, ozone absorbs UV at wavelengths between 44 and 80 nanometers but much less efficiently. This results in a rate of warming in the lower stratosphere that is less than the rate higher in the stratosphere, causing the temperature to increase with height.
For more information consult:
Middle Atmosphere Dynamics by Andrews, Holton, and Leovy The Dynamic Meteorology of the Stratosphere and Mesosphere by J.R. Holton
Try the links in the MadSci Library for more information on Earth Sciences.