Nico Castel in his volume on Strauss operas notes that “Er is the very Viennese address form for “you”. It is written with a capital Er, to distinguish it from er without a capital, meaning “he”. Likewise, Sie with a capital means “you” (feminine form), whereas sie without a capital means “she”. In this opera (Der Rosenkavalier) du and Er are used indiscriminately at the whim of the character, and the choice of one over the other is just a matter of preference at the moment.”
Ellen Rissenger (spent 16 years as a house repetiteur in Germany) spoke a German friend whose original degree was in 17.-18th c. German literature. They found a German Wikipedia article Pronominale Anredeform: sections dealing with this specifically are “Anrede mit Er/Sie” and “Neuzeit (1500-1800); at the end of the latter section, it says approximately “Since the spoken direct-address form has not been handed down in protocol, we aren’t very well-informed as to the origin, imitation, or how it spread regionally.”
Er/Sie were generally forms that someone of higher station used with someone of slightly lower station–although in Rosenkavalier it seems that they all use somewhat indiscriminately. Octavian and the Marschallin go back and forth between Er/Sie and Du. NOT only a specific Wienerisch thing, because it also did happen in Germany.