When the ball is dead and the clock is stopped, either team can make substitutions. The exception of course is if multiple free throws are to be attempted. Then an official will only accept substitutes before the final free throw or after the last free is successful. We already covered that point earlier.
In the situation stated, either team can make a substitute. The horn should be sounded as soon as the ball becomes dead (when the foul is committed) and the clock is stopped. Once the ball is placed at the disposal of the Team B player to make the throw-in, the ball becomes live. Meaning that substitutes would not be accepted.
A request for a time-out should also be considered in this situation. When the ball is dead, either team can be granted a time-out. When the ball is live only the team in control of the ball (player control must exist) can be granted a time-out. Therefore, once the ball is at the disposal of the player from Team B, Team A would not be granted a time-out if requested. Team B could request a time-out up to the 5th second and be granted a time-out.
Therefore, if Team A wants to make a substitution or request a time-out, it has to be done before the ball is placed at the disposal of Team B in the situation stated.