Firstly ensure that you have a good power supply (2.5A) and thick cable (reduce voltage loss). Secondly build your system incrementally starting with just the RPi operating headlesslessly, and make sure that it is nice and stable at each stage.
Edit: are you powering the RPi and display separately?
Listen up boys. This is important. I solved all my flakyiness issues.
Do not connect the sda/scl leads from the pie to the display.
That simple but I was lucky to find it.
Enjoy a stable system when using the 7" touchscreen.
Thank-you