Isn't there also a check engine light that sets after the battery has been disconnected? It's been a few years since I've had a battery out but, that light resets itself after 3 or 5 ride cycles. Nothing wrong. A reader will also reset the code but, probably not an issue.
As for the engine cutting out, I second what Bruce said. The battery cables are easy to not install correctly because of being on the downhill side of the bike and tucked under the frame edge. I had this one strand me on the freeway after 40-50 miles of misfiring and things cutting out. I thought I'd make it home but, didn't. The positive cable was finger tight and got so hot from the loose connection that it melted the lead terminal, ruining the battery (I had bought the bike that way a week earlier).
Was either of yours loose when you took it off? How old is the battery?

Also: have you or did someone else already clean and redo the grounds inside the electrical box area? The top grounding point on the engine is bare aluminum, with a hex screw clamping the negative terminations to that point. It corrodes. I had another bike with oddball misfiring on a ride. It would die, then resume, then die. It eventually set a check engine light. Got it home. Opened up the electrical cover. The engine grounding point is visible just ahead of the oil filler hose in this picture: (yellow ring terminal and hex head).

That termination jumps to another ground point on the frame. If this area isn't 100% it will cause all kinds of random issues. Jamie and Marty carry a nice braided jumper cable to go between the two ground points that improves on the factory part. Either make sure yours has it or make your own with a heavy gauge, highly stranded copper wire.
Even if all of that has been done, take out the screw and clean the terminal surfaces and the engine case with a wire brush or some sandpaper and reassemble. All electrical gremlins on this bike went away after cleaning and regrounding everything in there.