Break the problem down into logical pieces.
First of all, relay A needs to be driven by a latching circuit (a set-reset latch), which will then receive a signal to turn it on, and a signal to turn it off (or a single signal to make it change state--your choice). You need this so that relay A can stay on or off by itself, without needing any continuous external signal.
Secondly, when relay B is on, it needs to interrupt the signals going to the latch for relay A, so it cannot receive any commands.