If you have a copy of the service manual (paper or electronic form), follow the section on checking the ECU fault codes using the service connector.
If the problem occurs often or is easily reproducible, you could first clear the past fault codes, leaving only new ones added.
Then you'll be able to see what the current faults the ECU is reporting.
Also, be sure and check your battery posts are snug and clean.
The vibration tends to loosen fasteners over time.
That and rain/humidity cause corrosion on electrical contacts.
By yourself a tube dielectric grease at the automotive store and put a decent amount on every electrical connector you take apart. One tube is more than enough for the entire bike.
On my old wiring harness, I found a few green contacts that were iffy.