The overall structure of this passage is ii, V, I in A major. In closer detail, the first two bars alternate between D (IV) and Bm (ii), two closely related chords that share the same function. In even closer detail, the E# is melodic decoration, no need to over-analyse it. The E natural in the next group (along with the A# in the bass) hints at an F#7, dominant of the Bm chord reached on beat 3. There's a similar pattern in the next bar, a decorated Bm chord, a decorated D6, a hint of B7 leading into E7.
Mozart makes a feature of approaching notes from a semitone below in this passage. Sometimes it's harmonic, sometimes just decorative. This mix of repetition and variation is part of Mozart's genius.
The basic terminology is chromatic non-chord tones of the scale degrees ^5 dominant and ^2 supertonic.
The basic voice leading of that embellished passage and the half cadence is common enough that the author Gjerdingen named it "Indugio" and "Converging Cadence."
...explain why ...what is their purpose/function?
@LaurencePayne already pointed out these notes are decorative an provide color.
But I think it's important to say their essential purpose in this passage is rhythmic. The embellishment gives us the sixteenth note figure, actually it too has a name: cambiata.
Often embellishments like these happen with slower durations like quarter-notes and half-notes and become a more essential part of the melody.
Technically you would label them the same way, but I think it is good to make the distinction of rhythmic versus melodic purpose.
The E sharp is probably there because there has been a modulation to F sharp minor the relative key of A Major.
The A sharp looks like there is a modulation from f sharp minor to b minor. Both of these keys leading tones resolve the same way, by jumping up a third and then resolving down to the Tonic, which seems like a motif.
This is basically a V/V/V progression. The first measure shown is centered around F#. It uses the F# harmonic minor scale. This explains the E#, which is raised 7th degree/leading tone ascending into the F# (but is returned to natural when descending), but you can see A# in the lower voices which makes the chord at the end of the measure sound like F# major, the V of B. The next measure starts the same way as the first, being a partial sequence of the first measure. Again, it is based on a B harmonic minor scale, explaining the A#. At the end of the measure, the D# appears in the lower voices, creating a B major chord, which is V of E, which is the V of A. The next two measures give a very strong ending in E major, and if there is any question, the D# is included.