How do mountains affect temperature on both the windward side and the leeward side?
In 2 ways.
The main way that mountains affect temperature is by cause air to rise and then fall. This is due to changes in pressure. As you increase your elevation you will decrease the air pressure.
So given that you then need to look at gas laws, specifically Gay Lussac's law. It states that temperature and pressure are proportional. Therefore as pressure drops so does temperature. As air rises up the windward side of the mountain it drops in temperature. As it descends on the leeward side of the mountain it increases in temperature.
The second way temperature is affected is due to latent heat. This is heat that is trapped in water vapor. As the air rises and cools on the windward side of the mountain eventually it reaches the point of condensation.
On the chart above the red line represents how much water vapor air can hold at a given temperature. You will see that as temperature drops the amount of water vapor that it can hold decreases. When the temperature drops to the point that the actual amount of water vapor in the air is a the maximum (dew point) then that vapor begins to condense and form cloud.
During cloud formation, the latent heat trap in the water vapor is released into the air. This is explained in the following answer.
So the rate of temperature change per 1000m of dry air is 10 degrees, and for air with condensation is around 6 degrees. Therefore as cloud forms the air does not cool as fast. Once the air goes over the top of the mountain, it will descend and begin to heat. Since when it is heating it is becoming more dry it heats at 10 degrees per 1000m. So it will heat at a higher rate.
For example, a parcel of air that is 20 degrees and has 10 g of water vapour per kg of air rises 500m. The change in pressure cause the parcel to lose 5 degrees, and according to the chart above at 15 degrees, 10 g of water is the maximum amount it can hold so condensation occurs. If the mountain is 2000m then the last 1500m that the air rises it only cools at 6 degrees per 1000m or 9 degrees. Therefore at the top of the mountain the air is 6 degrees. The air will now descend the leeward side.
Since the air is warming it's ability to hold moisture increases, so there is no cloud formation. The rate that is warms is 10 degrees per 1000m. It has to descend 2000m therefore the air will warm 20 degrees. So the air that started at the base on the windward side at 20 degrees, is now 26 degrees on the leeward side.
All temperatures in Celcius.