I personally use the following, and will do a brief explanation:
Code:
on 1:quit:if ( $nick == $mnick && $me == $anick ) nick $mnick

ok, $mnick is your primary nick, $anick is your secondary nick, so if your primary nick quits, and you are as you secondary nick, you switch back to being the primary nick. This allows for you to change your nick to some 3rd nick, have your 1st nick disconnect, and you aren't automatically changed to your first nick. (I pasted this because I didn't think of this for a long time for some reason, and it is so simple!)

As far as auto identifying, a quick on notice does the job, have a look at: /help on notice