Doing righteous deeds when one is careless about prayer
Question

                In the past I did not pray regularly. I would pray for a few days, then stop for a few days, then go back to praying. I used to give a lot of charity, seeking the pleasure of Allaah, and I upheld the ties of kinship, doing that only for the sake of Allaah. Will the good deeds I did be rejected because my prayers were incomplete, or might Allaah accept them if He wills?.
Praise be to Allah.Negligence in performing prayers is a great sin, and a sign of extreme negligence, 
    because prayer  is the most important pillar of Islam after the Shahaadatayn (twin testimony of faith). Allaah warns those who take the matter of 
    prayer lightly and do not pray on time, as He says (interpretation of the meaning): 
“Then, there has succeeded them a posterity who have given up As-Salaat (the 
    prayers) [i.e. made their Salaat (prayers) to be lost, either by not offering them or by not offering them perfectly or by not offering them in 
    their proper fixed times] and have followed lusts. So they will be thrown in Hell.
Except those who repent and believe (in the Oneness of Allaah and His Messenger 
    Muhammad), and work righteousness. Such will enter Paradise and they will not be wronged in aught”
[Maryam 19:59, 60] 
A number of scholars were of the view that the one who misses a single prayer and delays it 
    until its time is over, with no excuse, is a kaafir. So what you have to do is to repent to Allaah from this great sin, and pray regularly on 
    time, as well as doing a lot of naafil prayers, in the hope that Allaah will forgive you and accept your good deeds. 
It says in Fataawa al-Lajnah al-Daa’imah (Fatwas of the Standing 
    Committee), 6/50: 
Question: 
Four years ago we went on a pleasure trip. During this trip I missed a prayer – 
    either Zuhr or ‘Asr, I can’t remember now – because I was being careless and lazy. Now I regret the sin that I committed and I ask Allaah to 
    forgive me for every sin. What do I have to do, and is there any expiation? 
The Standing Committee replied: 
You have to repent to Allaah sincerely, but you do not have to make up the prayer 
    you missed, because deliberately missing an obligatory prayer is major kufr [disbelief], as the Prophet  (peace and blessings of Allaah be 
    upon him) said: “The covenant that stands between us and them is prayer; whoever gives up prayer is a kaafir.” And he  (peace and blessings of 
    Allaah be upon him) said: “Between a man and kufr and shirk there stands his giving up prayer.” Narrated by Muslim in his Saheeh. There is 
    no expiation for that but sincere repentance. 
Secondly: 
The good deeds of a kaafir are of no avail before Allaah unless he becomes Muslim, 
    then his good deeds will benefit him and their reward will be written for him, as it says clearly in al-Saheehayn, where it is narrated 
    that Hakeem ibn Hizaam (may Allaah be pleased with him) said: 
I said, “O Messenger of Allaah, there are some things that I used to do as acts of worship 
    during the Jaahiliyyah, such as giving charity, freeing slaves and upholding the ties of kinship. Will I get any reward for that?” The Prophet 
     (peace and blessings of Allaah be upon him) said: “You entered Islam with the good that you had done before.” Narrated by al-Bukhaari, 1436; 
    Muslim, 123. 
Al-Nawawi (may Allaah have mercy on him) said: 
Ibn Battaal and other scholars were of the view that the apparent meaning of this 
    hadeeth indicates that if a kaafir becomes Muslim and dies in Islam, he will be rewarded for the good deeds that he did when he was still a 
    kaafir. They quoted as evidence the hadeeth of Abu Sa’eed al-Khudri (may Allaah be pleased with him) who said: The Messenger of Allaah  (peace 
    and blessings of Allaah be upon him) said: “When a kaafir enters Islam and becomes a good Muslim, Allaah records for him all the good deeds that 
    he had done previously, and erases thereby between ten and seven hundred (bad deeds) the like thereof, and each bad deed will only count as one, 
    unless Allaah forgives him.” It was mentioned by al-Daaraqutni in Ghareeb Hadeeth Maalik, and narrated from him through nine isnaads, in 
    all of which it states that if a kaafir becomes a good Muslim, every good deed that he did when he was still a mushrik will be recorded for him. 
Ibn Battaal (may Allaah have mercy on him) said, after mentioning the hadeeth: Allaah may 
    bestow His bounty upon His slaves as much as He wills, and no one can question Him for that. This is like what the Prophet  (peace and 
    blessings of Allaah be upon him) said to Hakeem ibn Hizaam (may Allaah be pleased with him): “You entered Islam with the good that you had done 
    before.”  And Allaah knows best. 
With regard to the words of the fuqaha’: “The worship of a kaafir is not valid, 
    and if he enters Islam it will not count,” what they meant is that it is not subject to shar’i rulings in this world, and there is no expectation 
    (at the time of doing it) of reward in the Hereafter, but if someone suggests that if he becomes Muslim he will not be rewarded for his good deeds 
    in the Hereafter, then that view should be refuted by referring to this saheeh Sunnah.  
And Allaah knows best.