Al-jawab billahi at-taufeeq (the answer with Allah's guidance)
According to the Ahlus Sunnah Wal Jama'ah, all Ambiya (Prophets, Alaihimus Salam) are innocent from all sins.
The Prophets (Alayhim Assalatu Wassalam), are infallibles of all sins, whether major, minor, or disbelief, and of all that is detestable/distasteful. It may be, however, that they commit insignificant lapses and inaccuracies [those are not true errors, as they usually indicate choosing the good, not the best. Secondly and most importantly, the Prophets, Alayhimus Salam, are immediately alerted to any lapses, and constantly directed by Allah towards the best].
And Muhammad (Sallallahu Alaihi Wasallam), is His beloved, His worshipper, His Messenger, His Prophet, His pious one, and His Chosen One. He never worshipped idols, he never associated anything with Allah, not even for a blink of an eye, and he never committed a sin, major or minor, ever.
(Fiqhul Akbar, Chapter: The Prophets Attributes, their infallibility, and the high status of the Prophet, (Sallallahu Alaihi Wasallam))
In addition, a prophet, being under the protection of Allah Ta'ala, can never show oversight or forgetfulness in things which are directly concerned with his prophetic and legislative function, but only in personal matters. (Al Bahrul Muheet)
It is advisable not to approach the status of Prophethood with enquiries except with the highest good manners. Prophets are the select of the Creator and like or above the angels in rank. We should take care, also, to focus on what is vital to our salvation and relinquish pursuits that are not only irrelevant but actually damaging to faith and works.
For more information, please refer to Tafseer of Ma'ariful Quran- concerning Adam (AS), Al Qasas 28:14,21:http://www.islamibayanaat.com/EnglishMaarifulQuran/English-MaarifulQuran-MuftiShafiUsmaniRA-Vol-1-Page-135-184.pdf
Also, with concerning Musa (AS), Al Baqarah 2:35,37:http://www.islamibayanaat.com/EnglishMaarifulQuran/English-MaarifulQuran-MuftiShafiUsmaniRA-Vol-6-Page-597-656.pdf
And Only Allah Ta'ala Knows Best.