what allows him to remain president ends
Strictly speaking, the war is not the (whole) thing which allows him to stay in office. His era continues up to the point when the successor is elected and there can not be legal elections during martial law. So, yeah, the war is the reason, but once the peace is achieved it still requires proper elections (no idea how long that takes in Ukraine as a whole) and then he's released from the office. So even if the peace came tomorrow I think it would take in minimum at least a few months until elections are open. Possibly even more as significant amount of Ukrainians are out of the country right now and they might want to secure option to vote for them too which might take quite a bit longer than few months.
But I have no doubt about it, they'll have fair elections when it's possible, Russia will try to influence the hell out of it and in the end Ukraine has new, fairly elected, president eventually.
I don't know about Ukrainian laws, but I'd suppose so. At least that's how martial law works in general, it's not easy to activate and there's written rules on when it has to end. And also I don't think it's the president alone who can decide for that to either way.
But again, I don't really know about their laws, just bits and pieces i've learned from the news. I barely know our own martial laws (or our law in general).