This is as per (my reading of) the opinion of Imam Ghazali in his book, The revivial of the religious sciences: coupled with my opinion.
We divide knowledge in two parts:
- Knowledge which pertains to our practical life:
In this there are certain types of knowledge which is compulsory to acquire. Acquiring such knowledge is an individual duty (فرض العين). Mostly this deals with beliefs, religious duties etc. These become compulsory to learn when we become eligibile to perform them. For example, you have the capacity to zakaat, and one year has passed with you in the capacity then you have to get all knowledge about zakat. Similarly for salat, fasting etc. It is not necessary to acquire knowledge about supernumerary prayers etc; although acquiring that knowledge is itself supernumerary.
There are other types of knowledge acquiring of which are duties imposed on the whole community (فرض الكفاية). In this context, I will now come to the point you posed about religious and worldly knowledge.
Firstly, this distinction between worldly knowledge and religious knowledge has to be understood keeping in mind our own unintentional inherent biases stemming from Western notions of difference between church-state. All knowledge is knowledge leading to Allah(swt) if learnt properly. In the Quran, we are commanded to look about the world and study it (for example see Quran 6:99) for this purpose. However, as a general rule, acquiring certain types of knowledge is praiseworthy, certain types is blameworthy and certain types is permissible. This distinction is made keeping the true purpose of acquiring knowledge in mind, which is of course to know more about Allah(swt).
The praiseworthy knowledge which is fard al-kifāya (or a duty incumbent upon the community) include amongst others Mathematics, Medicine, Sciences which should be learnt for agriculture, administration, industry, horticulture, weaving etc. Note that becoming expert in these subjects is not fard al-kifāya but enough should be known so that the nation can prosper. Also generally all knowledge connected with deen, i.e. commentary of the Quran, hadees, knowledge of revocation of verses, knowledge of books on authoritative transmission, knowledge of biographies of illustrious companions and narrators of traditions are in this category.
The blameworthy knowledge includes sorcery, talismanic science, juggling, gambling etc. The permissible knowledge includes poetry, history, geography, biology etc.
- Knowledge which pertains to our spiritual life. Your question doesn't deal with that.
Hope that answers your question.
Allah knows best.