Neck injuries are pretty common, and they can occur even just from sleeping in an awkward position. It seems like this is probably what happened to you, as you woke up from sleep with the symptoms. Fortunately, these injuries are rarely serious and they usually get better over a few weeks with adequate rest.
Although a pinched nerve can cause stiffness and pain in the neck, it is more common for this to be caused by a muscle spasm. There are two columns of muscles running up and down the two sides of the spine, and these are frequently sprained, resulting in spasm. Generally, ice to the area, rest, and an anti inflammatory medication like ibuprofen is all that is needed to clear up the pain although, as I said, the stiffness may linger for a few weeks.
If you feel like the pain is very severe or not improving, then you should go to see your primary care doctor
. Sometimes additional stronger medications are needed to help break the muscle spasm, and your doctor will be able to perform an examination and help you determine whether or not additional treatments are needed in your case.
Good luck, and I hope you feel better soon.