The atmosphere is mainly heated from the ground. The surface is warmed by the sunlight and this is distributed upwards to atmosphere and then to troposphere by mixing of air.
Temperature decreases with height as air pressure decreases with increasing altitude so the temperature.With increase in height, the number of molecules of air around you decreases, as the air rises to higher elevation it expands and as the pressure is lower at higher elevation the expanding air cools. Therefore, temperature decreases with an increase in altitude.