Stiff neck is a very common medical problem, most of the time related to chronic strain of the muscles that run up and down the two sides of the spinal column, which are known as the paraspinal muscles. I You are having chronic problems with neck stiffness, I would recommend that you go to see your primary care doctor
for advice on how to deal with the situation.
In more simple cases, you are right that various stretching and strengthening exercises might be able to make the difference, and your doctor can describe several of these to you. Similarly, it is important to identifying aggravating factors, such as your posture while at work (for example, sitting hunched over at a computer) and while sleeping, and trying to correct these.
In more severe cases of neck stiffness, there may actually be spasm of the muscles in the neck, which can sometimes require anti inflammatory medications or muscle relaxant medications in order to clear up.
Your doctor will perform a thorough examination of your neck and back, looking for evidence of spasm, strain, and weakness. Based on what they find, they will give you more specific recommendations.
I hope you are feeling better soon!