We need to have enough space for the longest of the two sub-/superscripts. For that we can calculate the maximum of both sub-/superscripts' widths and make a box as wide as the maximum:
\documentclass{article}
\usepackage{fixltx2e} % For \textsubscript
\makeatletter
\newcommand{\textsubsuperscript}[2]{%
\begingroup
\settowidth{\@tempdima}{\textsubscript{#1}}%
\settowidth{\@tempdimb}{\textsuperscript{#2}}%
\ifdim\@tempdima<\@tempdimb
\setlength{\@tempdima}{\@tempdimb}%
\fi
\makebox[\@tempdima][l]{%
\rlap{\textsubscript{#1}}\textsuperscript{#2}}%
\endgroup}
\makeatother
\begin{document}
A\textsubsuperscript{x}{yyy}B
A\textsubsuperscript{xxx}{y}B
\end{document}

I refrained from using mathmode and \text because \textsuperscript and \textsubscript may have more complex implementations than it would seem (see realscripts, for example).