From the SRD's section on Arcane Spells:
Rest
To prepare her daily spells, a wizard must first sleep for 8 hours. The wizard does not have to slumber for every minute of the time, but she must refrain from movement, combat, spellcasting, skill use, conversation, or any other fairly demanding physical or mental task during the rest period. If her rest is interrupted, each interruption adds 1 hour to the total amount of time she has to rest in order to clear her mind, and she must have at least 1 hour of uninterrupted rest immediately prior to preparing her spells. If the character does not need to sleep for some reason, she still must have 8 hours of restful calm before preparing any spells.
(emphasis mine)
The SRD doesn't mention the elves' ability to get by on four hours of sleep, but as I recall this ability didn't reduce an elf's need to rest; it only allowed them to be conscious during part of the time.
I'd say that applies here: The elf still needs eight hours of "restful calm" prior to preparing daily spells, but can be conscious during part of that time.
Divine Spells are much simpler:
Time of Day
A divine spellcaster chooses and prepares spells ahead of time, just as a wizard does. However, a divine spellcaster does not require a period of rest to prepare spells. Instead, the character chooses a particular part of the day to pray and receive spells. The time is usually associated with some daily event. If some event prevents a character from praying at the proper time, he must do so as soon as possible. If the character does not stop to pray for spells at the first opportunity, he must wait until the next day to prepare spells.
After the resting period/at the specific time of day, one hour is required to prepare spells. There's some more nuances to it (wizards can leave slots empty, for example) but the SRD does a good job of covering the rules clearly.