The experts have different viewpoints on this issue:
Taking into consideration verses 3 and 4 of surah Najm[i], some believe that all of the prophet’s sayings and actions originate from revelation.
Others believe that verse 4 of this surah has to do with Quranic verses and that only they are the sayings that originate from revelation, although the prophet’s (pbuh) tradition is also to be followed by us and none of his actions were out of personal desire.
It seems what one can be sure about regarding this subject is that none of the prophet’s (pbuh) sayings nor his actions were without the permission and verification of revelation and even the everyday things he would say and do that had nothing to do with religion weren’t out of desire, because in addition to being a prophet receiving revelation, he was an infallible, making him invulnerable to doing anything out of self desire or wrongness.
[i] “و ما ینطق عن الهوی ان هو الا وحی یوحی”
Without a doubt, the prophets all had a unique relationship [referred to as revelation] with Allah (swt), through which they would obtain the laws, rules and teachings of the religions they were sent for.
The true essence of this relationship is too complex and unknown to us and man isn't capable of comprehending it; nevertheless, this doesn’t mean that man is absolutely unfamiliar with it. In other words, “revelation” isn't an issue that must be disregarded just because its true essence isn’t comprehendible to us and we can't have an in depth and profound knowledge of it; what should and needs to be done is to try to get as familiar as possible and as much as our thought and intellects allow us to.
In Arabic, wahy or revelation refers to anything used to transfer knowledge or anything else to another person or thing. One thing that all forms of wahy share is the quickness, speed, concealment and mysteriousness that can be found in all of them.
The essence of wahy and what it actually is: Wahy or revelation usually has to do with knowledge and cognition, not stimulation and action, although when one acts, he makes use of the mind. Knowledge and cognition are a specific type of existence that are totally free of essence (mahiyyah).
In other words, revelation is a concept obtained from “existence”, thus not having an essence and not having the capability of being defined through genus and differentia. Therefore, revelation is too high to fall under one of the ten famous predicaments. The concept of revelation, like the concept of existence, has only one instance which has various degrees and levels.
Thus, the definitions that can be found for wahy, aren’t actually logical definitions, but they are merely descriptions. Add to that the fact that wahy isn't a normal relationship that can be experienced by all; it is limited to a small number of individuals, making it a concept that can't be defined by normal people.
Definition [Description] of wahy or revelation
Having said the above about the true logical definition of wahy, Allamah Tabatabai states: “Wahy is a special form of cognition and understanding inside the prophets which is only possible for those who have been graced by Allah (swt).”
He also says: “Wahy is an extraordinary and exceptional thing like inner cognitions, and complex and mysterious understanding which is hidden from the five senses.”
Now to answer the question:
Islamic scholars and thinkers have reached different conclusions on the issue through Quranic verses and hadiths:
Abdul-Razzaq Lahiji: “Anyone who perceives that the prophet (pbuh) ever did anything according to his own opinion without waiting for revelation, hasn’t truly understood prophethood and intellect says this person is closer to not being considered a religious individual, especially because he is directly contradicting the Quran when it says: “و ما ینطق عن الهوی، ان هو الا وحی یوحی” and it is very wrong to say that this verse is limited to some of the things the prophet (pbuh) does, not all of them, because all issues related to religion are equally in need of divine verification and revelation.”
Tafsir Nemouneh also says: “When the Quranic verse says “ان هو الا وحی یوحی”, it apparently covers more than just Quranic verses (meaning that it isn't only Quranic verses that the prophet (pbuh) needs revelation for), because considering its context and the verses preceding it, the verse is saying that the tradition of the prophet (pbuh) is also in need of revelation and in other words, not only doesn’t it cover the prophet’s (pbuh) sayings, but it also covers his actions and behavior as well; the reason for such being that in verses 3 and 4 of surah Najm, it has been clearly stated that: “Not he speaks out of his own desire, He relates to you only what is revealed To him”.
In his commentary on this verse, Allamah Tabatabai says: “The verse “he does not speak out of his own desire” itself is an absolute one; its absoluteness implying that nothing the prophet (pbuh) says is out of desire, yet considering that the word “صاحبکم” shows the mushrikin (idol worshippers) are the ones being addressed by these verses, one must say that when the verse is saying that the prophet (pbuh) says nothing out of personal desire, it means what he invites you to and the verses of the Quran he recites for you aren’t out of personal desire [and have nothing to do with him], but they are things that have been revealed unto him from Allah (swt) [and are what Allah (swt) has wanted to be passed on to you, hence breaking the absoluteness of the verse].”
Meaning what this verse verifies is whatever the prophet (pbuh) says regarding religion, stems from revelation, let it be preaching, ideology or guidance, not details that have to do with our material world.
Of course, this doesn’t mean whatever the prophet (pbuh) would say that didn’t have anything to do with religion was out of personal desire, such as if he would ask for a glass of water or for someone to come or go and the like, because in things that have nothing to do with religion, he was backed by infallibility, making him free of any form of mistake and wrongness. Therefore, by keeping this point in mind, it can easily be concluded that regarding such issues [that have nothing to do with religion], the prophet (pbuh) never does or says anything that is in contradiction with Allah’s (swt) satisfaction [or is wrong].
For further information, refer to: Ayatullah Hadavi Tehrani, Ta’ammulat dar Ilme Usule Feqh (series of kharej usul lessons), book one, pp. 34-67 (mabadiye sudure sunnat, martabeh va damaneye esmat).
 Raghib Isfahani, Mufradat Alfadhil-Quran, under the root word of “وحی”.
 For further information on this issue, refer to: Javadi Amoli, Ketabhaye Vahy va Nubuvvat dar Quran; Hadavi Tehrani, Mabaniye Kalamiye Ejtehad dar Bardasht az Qurane Karim, pp. 77-78.
 Muhammad Hosein Tabatabai, Al-Mizan (farsi translation), vol.2, pg. 159.
 Ibid, pg. 160; Also, for further information, see: Ayatullah Hadavi Tehrani, Mabaniye Kalamiye Ejtehad, ppg. 76-78; Abdul-Husein KhosroPanah, Qalamrove Din, pp. 117-130; and index: Revelation and How it Happens (Question 88).
 Abdul-Razzaq Fayyaz Lahiji, Gohare Morad, pg. 461.
 Tafsir Nemouneh, vol. 22, pg. 481.
 The mushrikin whom the prophet (pbuh) would invite to Islam and recite the Quran for, would say that he was falsely associating what he said with Allah (swt) and lying about Him.
 Mohammad Hosein Tabatabai, Al-Mizan (Farsi translation), vol. 19, pg. 42; Seyyid Mohammad Hosein Hoseini Tehrani, Mehre Taban, pp. 212-213.
 What is meant by something having to do with religion, is something that factors into one’s true salvation and prosperity in the hereafter whose mentioning is the responsibility of the prophet (pbuh).
 Ayatullah Abdullah Javadi Amoli, Tafsire Mozou’iye Quran, Sireye Rasoule Akram dar Quran, vol. 8, pg. 32.
 Note that what was said here is higher than what others sometimes say about the prophet (pbuh). They say that in addition to the prophet (pbuh) being a unique personality in receiving revelation, he himself was also a very high and matchless character in his time. Therefore, keeping this in mind, the prophet’s (pbuh) sayings can be divided into two categories:
a) The sayings that were revealed unto him such as Quranic verses
b) Wise sayings that belonged to himself that stemmed from his great personality
Therefore, if an infallible individual states something unrelated to religion, for instance if he makes a scientific point, what he says will be true for sure and without a doubt, the same way if he says something related to religion. Ayatullah Hadavi Tehrani, Ta’ammulat dar Elme Usule Feqh, book one, chapter on mabadiye suduriye sunnat, pg. 35.
 It can be deduced from the verse “و ما ینطق عن الهوی” that the prophet’s (pbuh) traditions and actions were also always with the permission of revelation. Nevertheless, if one believes that this verse doesn’t have such a vast meaning, covering even sayings that don’t have anything to do with religion other verses such as verse 50 of surah An’am and other similar verses imply such a fact. Javadi Amoli, Tafsire Mozoo’iye Quran, the chapter on the prophet’s (pbuh) tradition in the Quran, pg. 33