Any exercise that can help the muscles to have more optimism while riding, or relief sore on muscle. I also accept any special massage.
I prefer light jogging or running before. If that's not possible then some light stretching would be good since it tends to warm up the muscles for more rigorous activity later on. Do not forget to hydrate enough before cycling, during the pre-workout. Even skipping ropes works if you can do that.
Afterwards, a stretching becomes mandatory to relax the muscles. Also, while you are riding long stretches and get wound up and take a small break, do stretch the legs and back a bit, it helps in the long run. This would keep muscle soreness at bay, if not avoid it completely, but at-least delay the onset of it by a significant distance eventually.
The more you practice these habits in accordance to what your body tells you, you will be able to realise which muscle is going to ache/pain next and adjust your speed, posture, pit-stop, hydration accordingly.
I get enough stretching while getting my pants on before a ride. I take the first 10 minutes fairly slowly too, because its in traffic with lights. A drink of water before you go helps with pre-hydrating.
Afterward, do a cooldown ride for the last 5-10 minutes, not too fast. A hot shower helps, followed by clean fresh clothes. Then go clean your bike.
Some people use sports massage or self-massage with a roller to beat up tense muscles.
I have found that dynamic stretching, moving between yoga poses such as the downward dog and mountain climbers (lunges with your hands shoulder-width apart on the floor) so that you are able to do 8 repetitions, provides deep stretching after long rides.
Recently, I have worked on a series of seated, body weight movements with a goal of standing without using my hands to assist getting up. This is a feat for a mid 60's man.
Begin at a standing position and slowly lower yourself to the floor, knee first then seated in a crosslegged position. Open legs bent in front and turn to lower knees sideways on the floor, one heel in front and the other behind you. Then reach to the sky and pull yourself up to one knee. Then push with your other raised knee, foot planted in fron now to bring yourself to a standing position. Never use your hands to assist. Do this 8 times.
I'll answer a bit more broadly. Note that any links are not necessarily endorsements of the channel or organization who made the link, and that they're not guaranteed to be permanent. In all cases, I encourage you to google for alternative versions of the stretch, or alternate stretches targeting the same muscle group.
For many athletes, I suspect that just easing into your ride is sufficient. I think that the current recommendation by exercise scientists is not to stretch beforehand. In the worst case, this could lead to injuries, because you're stretching cold muscles.
If you're interested in further exploring pre-cycling warmups, you could search for dynamic stretching recommendations. Bicycling magazine (note: metered paywall) recently wrote one dynamic warmup routine. As you age, this type of warmup may become more beneficial.
Stretching key muscles
Afterwards, the quadriceps and hamstrings are obvious muscles to stretch. For the latter, I like to stretch them with a towel, as shown here, or you can replace the towel with a rubber exercise band.
We frequently get tight hip flexors. The first hip flexor stretch at this site is a good, basic stretch. I prefer a variation with a dowel. You can substitute a broom or similar implement for the dowel.
This requires a foam roller or a substitute. Free substitutes include tennis balls (find a nearby tennis court and search around the perimeter) or rolling pins. You would focus on trigger points, or particularly sore points in a muscle. These are a good way to massage the quadriceps and adjacent muscles. I think that the quads near the knee and the illiotibial band (outer edge of the thigh) are prime targets here. I think that ITB is frequently tight in cyclists.
A Thera Cane is a device for massaging the upper back and neck. These can get sore. Again, a free alternative to this is a tennis ball, although those will be bigger than the heads on a Thera Cane or similar device.
Electric massage guns perform similar roles. I don't think they're exact substitutes for foam rollers, but they both do perform pretty similar functions and you absolutely don't need a massage gun. If you use one, I'd recommend using the softer head, and take care not to press into the muscle too hard. This was discussed on the TrainerRoad podcast (starting at 1:22). Currently, I think I wouldn’t use a massage gun on my neck; it’s hard to reach, and it’s right by the spine. You might explore having a friend cautiously help you here.
Strength and conditioning
I think these are optional but potentially helpful. Cycling is a pretty static sport and we can develop muscle imbalances if we just focus on riding. Those can sometimes be the root cause of pain.
Push ups and bird dogs are two bodyweight exercises I tend to like to supplement with. You can search for other recommended core exercises.
If you have access to kettlebells, the basic kettlebell swing can be self-taught and is helpful. If you have a gym membership, you can seriously consider the deadlift and squat, but these require you to maintain good form, particularly as you add weight. I think that good form can be self-taught, but it's not a guarantee. For any weight exercise, coaching can be beneficial to help you master the basics of a movement. If you've had previous injuries, I'd more strongly consider finding a coach.
NashCat alluded to yoga and similar exercises. I think that spans both stretching and strengthening.
Last, bike fit
I've mentioned bike fit many times. When we buy bikes, we get a very basic bike fit by the salesperson. However, they aren't specialists in how our bodies interact with bikes. They may not catch more subtle issues like asymmetry (e.g. leg length functional asymmetry, or more rarely structural asymmetry). Also, as we age and as we get further into cycling, our bodies and preferences change. Many casual cyclists likely have their seats too low, but some performance cyclists think of that fact and end up pushing their seats too high and causing overuse injuries (personal experience).
While bike fitting is expensive, and while it's not actually a one-time deal (because bodies, needs, and preferences change), it is worth investing in a periodic fit. However, as with talk therapy, you may need to shop around for a good bike fitter, or to find a fitter that is good for you (i.e. the fitter-client interaction; a good bike fitter may just rub you the wrong way, or you might have found a pure roadie bike fitter but you're not that type of cyclist, etc). Good bike fits can prevent you from developing some injuries or sore spots in the first place. Depending on their expertise, some bike fitters may be able to recommend exercises to help you address weak points.