All Praise to Allah Subhanahu wa Taala and blessings of Him be on Prophet Muhammad peace be upon him His family and companions,
Considering Worship or Ibadah (عبادة) it would be better to understand its meaning first.Ibadah which we mean worship to God has a root word in Arabic (عبد) which means a Slave or a Servant.Now a servant is bound to do what ever his Master says ,So ibadah does not only mean to pray 5 times or fasting but there are many ways to do it. What ever Allah Subhanahu wa Taala has ordered us to do or not to do and then if we live in accordance to it then that is also a form of Ibadah.
So as per your query "what if intention of the person is not solely worship of God "
Now then in this case too the person would be fulfilling the commands of the Lord as Allah swt has ordered to earn Halal and feed your family so this would be following the Sunnah whether his intention is solely based on it or not he would be rewarded but would miss the rewards of the intention.
Sa’d ibn Abu Waqqas narrated that Messenger of Allah peace be upon him
said, “...whatever you spend you will be rewarded for it, even for a
morsel of food which you may put in the mouth of your wife.”
Now your query "What makes studying science permissible",So studying Science is permissible and would be benefitting to others ,Our scholars have mentioned that such amount of the worldly knowledge would be importantly considered as in maths if a person knows addition subtraction suffiecient for his daily life,In science hygiene or to treat some diseases etc.. but as you have already answered in your question that purification of the soul is important first so your intention would be to please Allah swt and the heart would be in constant remembrance of the Merciful Lord if one is able to purify his soul.
[Are] men whom neither commerce nor sale distracts from the
remembrance of Allah and performance of prayer and giving of zakah.
They fear a Day in which the hearts and eyes will [fearfully] turn
So sunnah is not only to worship or to just fast or pray for the whole day and night but to fulfill the rights of others as well for that one would need a job to take care of his family, it also constitues of any lawful acts a person does with God consciousness and in the hopes to earn reward from Allah Swt so devoting to Rabb is not meant to be always in the place of worship and a muslim could engage in worship all day and night by fulfilling his commands.
Narrated Anas: It was narrated from Anas that there was a group of the
Companions of the Prophet, one of whom said: "I will not marry women."
Another said: "I will not eat meat." Another said: "I will not sleep
on a bed." Another said: "I will fast and not break my fast." News of
that reached the Messenger of Allah and he praised Allah then said:
"What is the matter with people who say such and such? But I pray and
I sleep, I fast and I break my fast, and I marry women. Whoever turns
away from my Sunnah is not of me."(Nasai)
It was narrated that Muhajid said:
"Abdullah bin 'Amr said to me: My father got me married to a woman
from a noble family, and he used to come to her and ask her about her
husband. She said: What a wonderful man he is! He never comes to my
bed. And he has never approached me since he married me. He mentioned
that to the Prophet and he said: Bring him to me. So he brought him
with him and (the Prophet) said: How do you fast? I said: "Every day."
He said: "Fast three days of every month." I said: "I am able to do
better than that." He said: "Fast for two days, and break your fast
for one day." He said; "I am able to do better than that". He said:
"Observe the best of fasts, the fast of Dawud, peace be upon him:
Fasting for one day and breaking the fast for one day." 'Ata said:
"someone who heard him told me that Ibn 'Umar (said) that the Prophet
said: 'Whoever fasts every day of his life, then he has not
Examples of the noble companions of Rasulullah peace be upon him are remarkable as some of the notable companions were doing businesses but their heart remained in zikr of Allah Swt spending on their families too but when it comes to charity or for the sake of the deen they offer all their wealth health their lives everything.
Say, [O Muhammad], "If your fathers, your sons, your brothers, your
wives, your relatives, wealth which you have obtained, commerce
wherein you fear decline, and dwellings with which you are pleased are
more beloved to you than Allah and His Messenger and jihad in His
cause, then wait until Allah executes His command. And Allah does not
guide the defiantly disobedient people."(Quran 9:24)
So the real purpose is indeed worshipping our Lord but we should not reject the complete idea of worship our Lord ,we have to follow the way of Rasulullah peace be upon him as asked by our Rabb and he has fulfilled everyone's rights ,keeping beautiful relationship with family ,wives ,neighbours helping others teaching His companions and if someone would follow such way with avoiding all the haram acts and refraining from sins then he be able to attain the purified state of the Soul i.e Nafs ul Mutmainnah and he would be worshipping the Lord as mentioned in famous Hadith e Jibreel when Jibreel(As) asked him about Ihsan after asking Islam and Iman,
"....O Allah's Messenger (ﷺ) What is Ihsan (i.e. perfection or
Benevolence)?" The Prophet (ﷺ) said, "Ihsan is to worship Allah as if
you see Him, and if you do not achieve this state of devotion, then
(take it for granted that) Allah sees you." (Bukhari)
Allah Swt and His Messenger knows best.