Starting from the first law of thermodynamics, we know that heat travels from a hot recess to a cold enclosure. Extrapolating this to the movements of the earth, the air travels in the direction where the lowest heat concentration is found. Winds originate as a result of differences in atmospheric pressure and these differences are caused by different temperatures in the air. Cold air tends to move down, while hot air moves up. This displacement in the coasts because of the temperature difference generates that to reach the thermal equilibrium, the coldest air travels towards the hot air. The sea breeze travels to the land.
In the case of the night the process is inverse since the water serves as a thermal sink by accumulating more heat than the earth can accumulate. In this way the direction is changed and the breeze travels to the sea.