The best time to visit Costa Rica is during the dry season, from December to April. However this small country has many microclimates, so the weather can vary dramatically from region to region, all within one day.
The rainy season runs from May to November, with the heaviest rains falling in September and October, which should be avoided.
The Pacific Coast has a longer rainy season (March to November). The Caribbean Coast has a slightly different rainy season (May to December), except for July & August when the weather is very pleasant.