It sounds like a posterior vitreous detachment symptom with flashes and floaters of which there is info on search on this site. However, you are young to have this condition unless you are very nearsighted.
The nightime flashes are almost surely from the phenomena of phosphenes stimulated from the insertions of eye muscles into the sclera which stimulate the retina as they contract and there are six of these located in different areas of the eye.
I have been experiencing these symptoms of black/white flashes since I was a young child. Either everything goes completely black or it feels like there is a camera in front of my face, and I see the brightest light I have ever seen. Sometimes the light flickers and lasts for multiple minutes, continuously flashing, but usually it doesn't happen that frequently. Once I went completely blind for a couple of minutes. I thought it might be seizure activity, but I took an EEG, MRI, and EKG in high school all disproving macro seizure-related activity. I have always had perfect vision despite the random flashes that have been happening every day. My doctors all tell me that I'm fine, and a neurologist told me that it may be symptoms of atypical migraines, in which I don't feel pain (unrelated to eye care/vision). Do you notice you feel a lot of anxiety come on when you see flashes? It may signify an atypical migraine or just be affecting your eyes neurologically if your brain is trying to remove/handle extra sensory stressors.