I have had similar problems in the past and found the following to help immensely:
Warm up and stretch before, then stretch after exercise
Eat something carb/protein right after exercising
If you haven't worked out in a while, take it easy at first
Pay close attention to your form and make sure you aren't using equipment (including your bike) incorrectly
Stay well-hydrated
Get acquainted with what I like to call Vitamin I (Ibuprofin)