Not close to bedtime. Exercising close to bedtime -- within 3 hours -- may keep you from falling asleep. Aside from that, any time that you find convenient is probably ok.
Best in the morning. Exercise anytime is great! However, if given a choice, it is best to exercise in the morning as you get the benefits of the adrenaline surge throughout the day. Exercise at night, especially if it is vigorous, will raise your adrenaline levels when you are trying to sleep. This can make it more difficult to fall asleep or achieve quality sleep.