While playing badminton I often twist my ankle which is of course very unpleasant. Usually before starting playing, athletes prepare by warming up and stretching. Are there some exercises for that preparation stage (e.g. stretching) or other things that I could do to prevent rolling my ankle later in the game?
There are some improvements in technique that you can use, although they'll take practice.
This page describes good lunging technique to move efficiently and prevent injury. With regards to keeping your ankles safe, pay particular attention to the following:
The foot must point in the direction of the lunge
The heel must strike first
If you have an existing weakness or vulnerability to ankle injuries you could consider wearing an ankle support or doing specific exercises to strengthen it.
Note that I'm not a physiotherapist and you would do well to consult one to check that my general advice is appropriate to your situation.
Not specifically related to badminton, but I thought it would be a good fit here nonetheless.
One way to prevent ankle injuries is to rely on core strength, especially your hips and glutes. One way to train your hips is by executing the single-leg hip airplane.
This not only serves to remove dependence on your ankles (as you become more balanced), but also allows you to move with focused explosiveness, which will help you shift while playing badminton (or any sport that requires quick, shifty movements).
This is based on this article about how Stephen Curry overcame ankle injuries while playing in the NBA.
(Note: This solution was also referenced by @JamesBradbury)
Finally the method I used the most (which is also the most effective way, in my opinion):
The usage of an "Ankle Support Brace" gave my feet additional support, while still being flexible. Furthermoore, i actually do even jump smashes now - while that are one of the most "dangerous" shots in Badminton (for my ankles) I think the ability to make those shots shows the effectivity those support braces can provide.
I think they can be bought in usual sport shops.