When the weather is nice and warm but not too hot it's better to keep your windows open to allow fresh air inside the house.
On really hot days it's best to close the windows and turn on the air conditioner if you have an air conditioner.
However if you have no air conditioner then it's also better to leave your windows open and use fans to keep you cool.
If you keep your windows closed on a hot day and have no air conditioner then your house will be too hot as the hot air will stay trapped inside.
On nice days I always have all my windows open to allow fresh air in but because I have air conditioning I close up my windows and turn the air conditioner on to cool off.
The basic premise of having windows open or closed is that you should open your windows if it is cooler outside than inside, but keep them closed if it is warmer outside than in.
Also at night it is almost certain to be cooler outside than in your house, so you should keep your windows open to let the cool air in.