I know I have to get 8 hours of sleep and study my spell book for an hour to study and use spells. If I only study a certain number of spells and kept a few unstudied, can I prepare one later on when the need arises? How long will this preparation take?
Yes you can; it will take 15 minutes, longer if preparing more than a quarter of your total slots. According to the PHB, under Spell Selection and Preparation:
When preparing spells for the day, a wizard can leave some of these spell slots open. Later during that day, she can repeat the preparation process as often as she likes, time and circumstances permitting. During these extra sessions of preparation, the wizard can fill these unused spell slots. She cannot, however, abandon a previously prepared spell to replace it with another one or fill a slot that is empty because she has cast a spell in the meantime. That sort of preparation requires a mind fresh from rest. Like the first session of the day, this preparation takes at least 15 minutes, and it takes longer if the wizard prepares more than one-quarter of her spells.