Praise be to Allah.
This issue is known to the scholars as the issue of pairing or combining acts of worship. It takes many forms such as this one, which is combining an obligatory and a mustahabb action with one intention. If a person intends to do the mustahabb action, that will not be acceptable for the obligatory action. If a person fasts with the intention of 'Ashura, that will not be acceptable as making up for a missed Ramadan fast, but if he intends to make up the missed Ramadan fast and does that on the day of 'Ashura, then his making up the missed fast will be valid, and there is the hope that he will also attain the reward for 'Ashura, according to some scholars.
Ar-Ramli (may Allah have mercy on him) said in Nihaayat al-Muhtaaj (3/208): If he fasts in Shawwaal to make up a missed fast, or in fulfilment of a vow, or otherwise, or on an occasion such as the day of 'Ashura, he will also attain the reward for the voluntary fast. This was stated in a fatwa by my father (may Allah have mercy on him), following al-Baarizi, al-Asfooni, an-Naashiri, the faqeeh ‘Ali ibn Saalih al-Hadrami, and others, but he will not attain the full reward that comes from doing what is required, especially if he missed Ramadan and fasted Shawwaal to make up for it. End quote.
It says something similar in Mughni al-Muhtaaj (2/184) and Hawaashi Tuhfat al-Muhtaaj (3/457)
Shaykh Ibn ‘Uthaymeen (may Allah have mercy on him) said in Fataawa as-Siyaam (438): If a person fasts the day of ‘Arafah or the day of 'Ashura, and he still owes fasts from Ramadan, his fast will be valid, but if he intended to fast that day to make up for a missed Ramadan fast, he will have two rewards: the reward of the day of ‘Arafah or the day of 'Ashura, and the reward for making up the missed fast. This applies to voluntary fasts in general, that have nothing to do with Ramadan. But with regard to the six days of Shawwaal, they are connected to Ramadan, and can only be done after making it up. If a person fasts these days before making up missed Ramadan fasts, he will not attain the reward for them, because the Prophet (blessings and peace of Allah be upon him) said: “Whoever fasts Ramadan then follows it with six days of Shawwaal, it will be as if he fasted for a lifetime.” And it is well known that if a person owes missed fasts, then he cannot be regarded as having fasted Ramadan until he completes the days that he owes. End quote.
So what one should do is hasten to make up what one owes; this is more important than doing voluntary actions. But if he does not have much time and he cannot make up all the days that he owes, and he is afraid of missing out on the fast of a day of virtue such as 'Ashura or the day of ‘Arafah, then he may fast with the intention of making up the missed fast, and there is the hope that he will attain the reward of 'Ashura and ‘Arafah as well, for the bounty of Allah is immense.
And Allah knows best.