If a person repents from one sin whilst persisting in another sin, then the sin from which he has repented will be forgiven for him, according to the correct scholarly view, but the sin from which he has not repented will remain as it is and will not be included in that act of repentance, according to scholarly consensus.
See the answer to the question: Is repentance from one sin valid when one is persisting in another sin?
If a disbeliever or apostate becomes Muslim whilst persisting in some sin from which he has not repented, his becoming Muslim is valid according to scholarly consensus. But will he be forgiven for the sin from which he has not repented, as a result of becoming Muslim? Concerning this there are two scholarly views.
Shaykh al-Islam Ibn Taymiyah (may Allah have mercy on him) summed up this difference of opinion when he said:
… The second principle is: whoever has committed some sins and repents from some of them but not others, his repentance will only lead to forgiveness of those from which he has repented. As for that from which he has not repented, it will remain subject to the ruling on one who has not repented, not the ruling on one who has repented.
I do not know of any dispute concerning that, except with regard to a disbeliever if he becomes Muslim. In that case, his becoming Muslim implies that he has repented from disbelief, so by virtue of becoming Muslim he is forgiven for the disbelief from which he has repented. But will he be forgiven for sins that he committed whilst he was a disbeliever and from which he has not repented as a Muslim?
Regarding this matter, there are two known views:
The first view is that he will be forgiven for all his sins, because of the general meaning of the words of the Prophet (blessings and peace of Allah be upon him): “Islam erases that which came before it.” Narrated by Muslim. And Allah, may He be exalted, says (interpretation of the meaning): “Say to those who have disbelieved [that] if they cease, what has previously occurred will be forgiven for them.” [al-Anfaal 8:38].
The second view is that he does not deserve to be forgiven for sins that he committed after he became Muslim except those from which he has repented. So if he became Muslim but persisted in some major sins that are less grievous than disbelief, then in that regard his ruling is the same as that on others who commit major sins.
This view is what is supported by general Islamic principles and textual evidence. In as-Saheehayn it is narrated that Hakeem ibn Hizaam said to the Prophet (blessings and peace of Allah be upon him): O Messenger of Allah, will we be brought to account for what we did during the Jaahiliyyah? He said: “Whoever among you does good in Islam will not be brought to account for what he did during the Jaahiliyyah, but whoever commits evil after becoming Muslim will be brought to account for what he did both before and after [he became Muslim].”
This text indicates that accountability for deeds will only be waived for what was done during the Jaahiliyyah in the case of one who does good, not in the case of one who does not do good. If a person does not do good, he will be brought to account for what he did both before and after [he became Muslim], and the one who does not repent from a particular sin has not done good. End quote from al-Fataawa al-Kubra (5/278).
These two views are agreed that the person’s becoming Muslim is valid and that it erases disbelief; the difference of opinion has to do with forgiveness of sins, from which he has not repented, by virtue of his becoming Muslim.
He (may Allah have mercy on him) was asked about a Jew or a Christian who becomes Muslim: does any sin remain on him after he becomes Muslim?
He replied: If he becomes Muslim both inwardly and outwardly, he will be forgiven for the disbelief from which he repented by becoming Muslim, and there is no difference of opinion concerning that. As for sins from which he has not repented, such as if he persisted in a sin, in wrongdoing or in some immoral action, and did not repent for it when he became Muslim, then some of the scholars said that he will be forgiven for [his misdeeds before becoming Muslim] by virtue of his becoming Muslim.
However, the sound view is that he will only be forgiven for what he repents from [after becoming Muslim], as it is proven in as-Saheeh that the Prophet (blessings and peace of Allah be upon him) was asked: Will we be brought to account for what we did during the Jaahiliyyah? He said: “Whoever does good after he becomes Muslim will not be brought to account for what he did during the Jaahiliyyah [time of ignorance before becoming Muslim], but whoever continues to do bad deeds after becoming Muslim will be brought to account for what he did before and after [becoming Muslim].”
Doing good after becoming Muslim means adhering to doing what Allah enjoins and refraining from what He forbids. This is what is meant by repentance in general. So whoever becomes a Muslim in this sense, all his sins will be forgiven. End quote from Majmoo‘ al-Fataawa (11/701).
If a disbeliever becomes Muslim, but he loves alcohol and persists in drinking it, his becoming Muslim is valid according to scholarly consensus, but will he be forgiven for drinking alcohol [before becoming Muslim] by virtue of becoming Muslim? This is the matter concerning which there is a difference of scholarly opinion.
And Allah knows best.