First off, there can be many different reasons to have some pain with deep breathing. Some of the more common reasons include inflammation of the muscles between the ribs or the cartilage connecting the ribs to the sternum. Additionally, poorly controlled asthma
or an infection in the lungs like a pneumonia
can also cause this. More serious causes could include an air leak in the lungs, a blood clot in the lungs, or a problem with the heart, although there are usually additionally symptoms a the same time. Regardless, I would recommend going to see your primary care doctor
about this. They will be able to perform a complete physical examination and, if there are any concerns, order additional tests.
You should also mention to them the problem with blacking out. Based on the way your question describes it, it sounds like you might be experiencing these symptoms because of needless breath holding. The natural response of the body to oxygen deprivation (breath holding) is feeling dizzy and at a minimum I would suggest not doing this any more until you can be seen by your doctor. When they examine you, they'll be able to help figure out whether this dizziness is a concerning problem or is just related to the breath holding.