I think the ideal time to take it is at the end of summer of your sophomore year (after having taken organic chemistry), when the material that is covered on the test (bio, general chem, organic chem) is still fresh in your head. The amount of time to prepare will depend entirely on your style of studying, the amount of hours you study each day, and how much of the material you remember from class - but I'd say the typical range is 1-3 months.
That gives you a year before applying to retake if you aren't happy with your scores as well.