Many years ago I experienced an intermittent electrical issue, that was a real challenge. It also makes for some tall tale bench racing sessions!
Not to bore you with all the details, it ended up that someone had tested one of the coils by using a tester that "pierced" the wire. What they did was to put a piece of black electrical tape over said hole... well after replacing almost every electrical component on the bike (some more than once) it was found that only 1 strand of wire attached the generator coil to the rest of the system. When the bike got hot, the "Mysterious" problem would rear it's ugly head!!
Once the break in the wire was found and sliced together, the problem was solved.
My suggestion is that you go through the entire wiring harness and make sure all the connections are clean and secure. Also visually inspect the wiring to see if it has worn through and could possibly be shorting out on something..
This is the least expensive initial troubleshooting that you can do. It's something that I would examine before I did anything else.
Good luck!