Add a new event for the connection:

Code:
ON *:CONNECT: {
  if ($network == undernet) {
    .msg X@channels.undernet.org login username password
    .timer 1 5 .mode $!me +x
  }
}

I don't know what the response from X is, so using a timer here is a shortcut way of doing it. The longer way would be to change the mode upon receipt of X's response.