I can't write the entire thing this moment, but on close you would save your open windows to a file. A single alias could be called on each server using scid -a. This alias would loop through $chan(i) and $query(i) and use $status for the server status (so you know if you want to connect or not on start). On start, you would go through these saved values.

Of course, rather than saving a session it may be better just to have mIRC connect to your prefered channels and servers on start, and just restore the state of any query windows you had open.