This would work, and it also doesn't.
If someone bans more than just 1 ban that affects you, you're only going to unban it once (or it might just be spammed in a single line where you unban several times.)
mode # -qaohv+b $nick $banmask
You're banning yourself in that again.
You're also putting just ONE $nick and you'll need 5 of those.
Instead use the 2nd line after but edit that.
mode # -qoahv+b $nick $nick $nick $nick $nick $address($nick,2)
And for ChanServ, you might want to use more of those commands even if other services use Anope. ChanServ is a bit more popular from what I've seen so use that commands because they guaranteed to work (unless the nick has exception.)