You are very wise to link your intestinal health to sleep problems. Some thoughts come to mind in solving this.
An excellent book with a lot of self quizzes to figure out what your issues are along with advice for how to tackle them is "The Food Intolerance Bible" by Anthony Hayne.
Have you done a DNA stool test to look fornacteria, fungi, and parasites are living in your microbiome? Genova Diagnostics GI Effects covers all of these, or there are also good tests from DiagnosTechs (GI-Map) and uBiome.
Have you looked into the possibility if celiac disease, which can damage your gut lining and create intestinal permeability, or other food allergies? Cyrex Labs has several tests that might be useful.
You might also want to look into the 4R protocol, which walks you through the steps of healing gut permeability.
Probiotics, insoluble fiber, digestive enzymes, gut nutrients like l-glutamine, certain pharmaceutical or botanical medications (which can kill certain and actors in your gut) and avoiding food irritants may all be components of a solution.
Having gone through this myself and with other family members, I've found it can take several months to fix one's gut, by patiently working the issues.
Best wishes...