Pain in ribs as you are saying accompanied with breathing can possibly be because of several factors.
(a) Posture related (Cellular device / headphones / anything hard that might be putting pressure onto your Ribs while sleeping)
(b) Spasm related (muscular spasm could be one of the major causes that people feel such kind of pain, usually pain subsides as the spasm is relieved by medication / naturally)
(c) Chest Infection.( rarely if there is infection in chest cavity it may cause pain , check if you are having prolonged coughing,/ excessive mucous secretion by lungs, pain can be linked with coughing,, at times even asthma can be the cause)
(d) unknown cause (several radiological and biological tests should be able to diagnose the exact cause, (x-ray, MRI, Tissue Biopsy)
Next Steps
Consult a physician , to figure out the exact cause.
Health Tips
Eat healthy, rule out other causes. STAY HEALTHY