It is slightly more complicated with a nick change, because that event does not define $chan, but instead triggers 1 time for all channels you share with that nick. Also, :NICK: uses $nick for the old nick and $newnick for the new nick.

I am going to assume that you are wanting to deal with this only with 1 channel, and am going to alter the code so you can have the shared code be used by both :JOIN: and :NICK:

These events would call the alias having the 1st parameter is the channelname and the 2nd is the nick, and the 3rd is either blank or the number of seconds. I am also going to put some of the code inside the alias to avoid the hassle of having the timer evaluating the channel name in the unlikely event that you use this with a channel named '#' or #$version

I am also removing the names assigned to the timers, to allow it to create a unique name instead. The existing code does not work correctly if 2 matching nicks are being handled at the same time, because the timers for the 2nd nick were replacing the timers for the 1st nick

Code
ON @*:JOIN:#channel: { if (anon* iswm $nick) badnick_alias $unsafe($chan $nick) }
ON *:NICK: { if ((anon* iswm $newnick) && ($me isop #mychannel) && ($newnick ison #mychannel)) badnick_alias $unsafe(#mychannel $newnick) }

alias badnick_alias {
  var %chan $1 , %nick $2
  if ((Anon* !iswm %nick) || (%nick !ison %chan)) return
  if (!$3) {
    .notice %nick Please change your nick within 2 minutes, or you will be kicked.
    .timer 1  30 badnick_alias $unsafe($1-2  30)
    .timer 1  90 badnick_alias $unsafe($1-2  90)
    .timer 1 120 badnick_alias $unsafe($1-2 120)
    return
  }
  elseif ($3 == 30) /notice %nick This is your second warning change your nick or be kicked 1 minute remaining!!
  elseif ($3 == 90) /notice %nick This is your LAST warning change your nick or be kicked 30 seconds remaining!!
  elseif ($3 == 120) kick %chan %nick Please change your nick
}