This is my recommended list of best times to visit Beijing:
Late-August to late September: lowest pollution level in the year, lots of blue skies, and perfect temperature not too hot and not too cold
Beginning of May to early-June: relatively lower pollution and comfortable temperature, with the benefit of low level of tourism in the city so attractions are not that crowded
Chinese New Year: very cool to experience Chinese New Year in Beijing, it's quite unlike anywhere else in China (or the world). It's very cold during this time, but upside is not many tourists are here so it's not crowded at attractions. Chinese New Years are usually in late January or early February.
In my opinion the worst times to visit Beijing are:
October 1st to October 15th: this is the time around the National Day, which falls on October 1st. It is a nightmare to travel in Beijing during this time because it is crowded everywhere you go. We locals try to stay indoors as much as possible as Chinese people from all over the country visit Beijing during this time
November and December: very high pollution during this time. It is getting better every year so maybe in 5-10 years this is not relevant anymore, but for now I do not recommend visiting during this time. We in the north burn coal to keep warm, so this is why pollution is always very bad in the winter
January/February but not during Chinese New Year: Chinese New Year is very cool in Beijing, but the rest of January and February is boring and polluted. It's also very cold in Beijing during this time so please do not visit you will get a bad impression of Beijing!
I have made some useful charts to help you decide
Average air pollution by month: the lower the better. Anything below 50 is usually considered good by the UN. It's clear from this chart that summer is the least polluted times of the year and November-December are the most polluted times of the year. Data is from US Embassy.
Average temperature by month: expressed in centigrade. 20C is 68F. April-May, September-October are very comfortable times to visit. Any other time of the year is either too hot or too cold. Data from holiday-weather.com
Average nightly hotel rate by month in Beijing: this is a useful gauge of how many tourists there are in the city. It's clear that June through October are the busiest times for tourism in Beijing. January-May are the least busy time in Beijing. Data from kayak.com