Answer:
Thunderstorms are formed by a cold front and warm front meeting each other. Moisture must be present and energy (from the sun) is needed to cause the moisture to rise into the air. This rising action causes bumpy flying (thermals) and friction of the water against the atmosphere.
The static energy builds up to tremendous levels. If the pumping action of the system is strong enough, you will see lightening start to occur.
The energy from the sun is an important portion of this mix. That is why you will tend to see the largest storms occur in the afternoon, during the warmest portion of the day. They tend to get weaker through the night, although energy from warm ground or massive amounts of moisture in the air cause issues to develop at different times.