When playing guitar, the fingers need to be extended flexibly in order to hit the right part of a string. Is there any exercise to make them more flexible when I am not playing guitar?
The single best thing you can do to improve flexibility, speed or strength for playing guitar is to play the guitar. A lot.
Try different styles as this will provide bbth a benefit from speed and strength, but also open you up to different types of music, eg fingerpicking, classical, flamenco, rock, metal etc