The basic principle concerning selling is that it is permissible because Allaah says (interpretation of the meaning):
“Allaah has permitted trading and forbidden Ribaa”
al-Jassaas said: This is general in meaning and indicates that all transactions are permissible.
Ahkaam al-Qur’aan, 2/189
This is as far as the general principle is concerned. But if the item sold is haraam, or if it is usually used for haraam purposes, then it is not permissible to deal in it, either buying or selling. Based on that, one of the following must apply to these books that are mentioned in your question:
Either they are useful books which will be of benefit to the reader even if they are not about religious topics, such as history, politics, physics, computer science, etc and do not include – as far as you know – anything haraam, such as lies or promotion of evil or anything that would deceive and mislead people. These come under the principle mentioned above, which is that it is permissible to sell them according to sharee’ah. If it is permissible to sell them then it is halaal for you to use the money you get for your spiritual and worldly interests.
Or they are books that are haraam in and of themselves and are harmful to the reader because they include lies, distortions of the facts and of religious truths, corruption of morals, religious commitment and beliefs, or changing the meaning of modesty in women and chivalry in men – as is the case with most novels and plays, whether Arabic or foreign. It is haraam to sell these kinds of books; rather they must be destroyed and it is not permissible to make use of the price, because the Prophet (peace and blessings of Allaah be upon him) said: “When Allaah forbids a thing to people, He also forbids its price.” Narrated by Ahmad, 2956; classed as saheeh by al-Albaani in Ghaayat al-Maraam, 318.
And Allaah knows best.