You could start with "fixing the prompt": some of those answers deal with modifying the (bash or zsh) prompts to send escape sequences which change the window title. The background color for xterm would be just another escape sequence, part of the same group of Operating System Commands:
OSC Ps ; Pt BEL
OSC Ps ; Pt ST
Set Text Parameters. For colors and font, if Pt is a "?", the
control sequence elicits a response which consists of the con-
trol sequence which would set the corresponding value. The
dtterm control sequences allow you to determine the icon name
and window title.
...
The 10 colors (below) which may be set or queried using 1 0
through 1 9 are denoted dynamic colors, since the correspond-
ing control sequences were the first means for setting xterm's
colors dynamically, i.e., after it was started. They are not
the same as the ANSI colors. These controls may be disabled
using the allowColorOps resource. At least one parameter is
expected for Pt. Each successive parameter changes the next
color in the list. The value of Ps tells the starting point
in the list. The colors are specified by name or RGB specifi-
cation as per XParseColor.
...
Ps = 1 0 -> Change VT100 text foreground color to Pt.
Ps = 1 1 -> Change VT100 text background color to Pt.
With xterm (not necessarily for "xterm" imitators...),
printf '\033]11;blue\007'
printf '\033]11;white\007'
changes the window background to blue and then white.
Unlike settings for "ANSI colors", the dynamic colors persist, will not be reset by other escape sequences.
Oddly, xterm: how to change the background color? suggests "two" (actually one) different way for setting the background color, but that's not useful for your purpose.