Regarding diet, I started observing the effects of everything I ate and adjusting accordingly, somewhat like an elimination diet. I was actually really clueless at first and had numerous deficiencies as a tradeoff for some of the symptoms disappearing (which was great but not sustainable). Over the span of years, this has improved and today I have no deficiencies and only relatively mild symptoms remain.
The biggest breakthrough was limiting fermentation, by taking the FODMAP IBS diet to its natural conclusion, and eliminating everything that would ferment (and thus increase intestinal microorganisms, which for me were imbalanced). What prompted me to do this was trying 2 similar probiotic formulations, only one of which had FOS. The one with FOS caused a huge flare up. So I greatly reduced fermentable things ("resistant starches," "soluble fiber," "FOS," "FODMAPs", fructans, sugar alcohols...). Caprylic acid supplementation really reduced fermentation whenever I made a dietary mistake.
I googled that idea and found the blog of Dr. Norm Robillard which advocates for a similar low-fermentation diet. Interestingly, the people who commented on his site seemed to divide into 2 camps: low-fermentation people vs. those who did well on the opposite diet (high starch / fermented foods).
Adding S. Boulardii then reduced my symptoms further (brain fog, chronic intestinal inflammation) and I feel pretty decent now.
I cannot yet figure out how to make it so my intestinal microflora is balanced enough that eating fermented and/or fermentable foods wouldn't destroy me. I'm still working on that in my spare time.