Basically, wind is caused by two (or more) masses of air with different air pressure running into each other.
High pressure areas always move toward adjoining low pressure areas. The attempt to equalize the pressure between the different air masses results in wind.
On a small scale, consider air over a shoreline. During the day, the ground releases more absorbed insolation (incoming solar radiation—sunshine) than does the water. Though they may receive the same amount of insolation, the water retains more of it.
The air above the ground is heated by the released insolation and rises while its pressure sinks (hot air rises and hot air has low pressure). The air above the water remains cooler and has higher pressure. Since high-pressure areas try to infiltrate low-pressure masses, a cool wind, called a sea breeze, comes ashore from the water.
At night, the water still has heat it absorbed during the day while the ground has already released a lot of its supply. The air over the water, then, becomes warmer with lower pressure than the air over land.
Following the rule that high pressure seeks to replace low pressure, the wind shifts and a land breeze blows out to sea.