Before and after practicing is highly recommended that you do some stretching to avoid hurting yourself. It is easy to demand lots from your neck, back, arms and hands during practice. Make sure you have stretched them accordingly. If you feel pain, first stop and take a break, if the pain persists you might consider see a doctor.
I never felt pain other than when heavily practicing or one time after playing nine hours straight on a party. The pain, which was more about tired muscles, went away after some resting. Therefore I'm not experienced with pain problems cause by guitar play. Mind that this stretching routine is very simple and may not be complete enough for you.
Place your arm across your chest and with the help of the other arm pull it a little bit more. Count slowly to ten for each arm.
Now put your arm behind your head and use the other arm to grab your elbow and pull. Again, count slowly till ten for each arm.
With your arm straight, fingers up and the palm facing outwards, gently pull your fingers (including the thumb) in your direction. You will feel your wrist and forearm stretching. Now point the fingers down, palm outwards and pull them again. Do that for the other arm, always counting to ten.
Pain attention to this one, you should be careful to not pull too hard and hurt yourself. It is similar to the above but this time the palm of your hand is facing inwards and your fingers are pointing down. Pull gently to stretch the top part of your forearm.
Do exercise regularly especially if you are practicing for long hours. Make sure you have the appropriate breaks and respect your body constraints. Remember, not paying attention and hurting yourself will just prevent you from playing.