One
of the best ways to stretch is referred to as static stretching,
in which you stretch each muscle group slowly and gently, until
a mild amount of tightness (not pain) is felt in the muscle.
You then maintain this position for about 30 seconds, or until
the muscle begins to relax. As you hold the stretch, the feeling
of tension should diminish. If it doesn't, just ease off slightly
into a more comfortable stretch.
After holding the easy stretch, move a fraction of an inch farther
into the stretch until you feel mild tension again. This is
called the developmental stretch. This should be held for another
5-30 seconds. This feeling of stretch tension should also slightly
diminish or stay the same. If tension increases or becomes painful,
you are over-stretching. Ease off a bit to a comfortable stretch.
The developmental stretch reduces tension and will safely increase
flexibility. Repeating this process a few times for each muscle
group will give the best results. 
The key to stretching is to be relaxed while you concentrate
on the areas being stretched. Your breathing should be slow,
deep and rhythmical. Don't worry about how far you stretch.
Your muscular suppleness will increase the more your stretch.
Incorrect technique
The rapid, jerky movements involved in ballistic stretches,
or bouncing, are ineffective and can lead to injury. As you
bounce, your muscles respond by contracting, to protect themselves
from over-stretching. Thus tension develops in the muscle and
prevents it from being fully stretched.
Also, bouncing causes tiny tears in the muscle. This leaves
scar tissue that can make the muscles less flexible than they
were before.
When You Should Stretch
Pre
and post ride
Stretching will start the blood circulating through the muscles
and warm them up to the tasks ahead. Once on the bike, though,
don't forget to put in a good warm-up before any hard efforts.
It is suggested that you experiment with stretching for 5-10
minutes before and after you ride. The areas of your body that
tend to tire first are the ones that you should pay attention
to in preparation for your ride.
During the ride
After sitting in the saddle for several hour, specific parts
of you body will begin to get tight and tired. If you are losing
efficiency whilst riding, slow down and do several stretches
to help your body to rest and stretch out the tightness that
has developed. Make sure you practice these "on the bike stretches"
at a safe speed and with no other cyclists or traffic around
before you attempt them while riding in a group.
At other times. 
Two-to-five minutes of stretching, several times a day, is excellent
for keeping the muscles fined-tuned and tension free. Stretching
is not something to do just as part of a workout. If the timing
of your workout doesn't allow for stretching - say you've got
to squeeze your cycling into a tight noon hour - then any other
time of the day is fine. At home you can stretch while watching
TV. This is a particularly good time to do leg and back stretches
and to massage and elevate your legs to reduce the feeling of
tightness and fatigue after a hard ride. Stretching in the car
or at the office are other occasions to consider as stretching
times.
When Not to Stretch
There
are times when stretching can do more harm than good. For example:
When
you have an injury.
Stretching torn muscles or tendons can lead to further injury.
What they need is rest to heal properly, not stretching. Return
to stretching only when the injury has healed. 
When muscles are cold.
While proper stretching will aid your warm-up process, caution
must be taken when muscles are cold. A cold muscle can be compared
to a dry sponge. Trying to stretch it is usually ineffective
and can even result in small tears in the muscle. A warm muscle
however can be compared to a wet sponge; it is far more flexible
and supple.
Wear tights while warming up in cool or cold weather and maybe
even warm-up by jogging or riding the bike for a few minutes
before stretching.