Can you keep Miraak alive and get his help to defeat Hermaeus Mora?
No, there is simply no way to finish the quest without killing Miraak. Furthermore, there is no way to kill Hermaeus Mora (in the base game/DLC, at least).
However, I found this oddly specific mod that apparently allows you to do exactly what you've described in the question. The mod allows you to cast Bend Will on Miraak and team up with him against Hermaeus Mora, as well as unlocks Miraak as a follower and marriage candidate.
Unfortunately, nothing on the page indicates whether or not this mod is compatible with Skyrim Special Edition. This appears to be a port of the original mod that works in the Special Edition, but it looks like it was combined with other mods.