I always had the doubt and I would like to ask when and why the term Ayatollah and Hujjat ul-islam began to be used to refer to our scholars. I would like to explore about its origin and meaning. Unfortunately I have not found information yet.
Considering that the word "Ayat" literally means sign or symbol, the expression 'Ayatollah' can be used to refer to any signs of God. That is to say, God's every single creature is in fact a sign of God's existence, power and omniscience. There are verses in the Quran that are referring clearly to the same point:
«و فی الأرض آیات للموقنین و فی أنفسکم أفلا تبصرون»
And in the earth there are signs for those who are sure, and in your own souls (too); will you not then see?
The term 'Hujjat ul-islam' has a more sublime meaning as compared to 'Ayatollah', though it is not considered or treated as such in public utterances. This title has been taken from narrations such as the following:
«وَ أَمَّا الْحَوَادِثُ الْوَاقِعَةُ فَارْجِعُوا فِیهَا إِلَى رُوَاةِ حَدِیثِنَا فَإِنَّهُمْ حُجَّتِی عَلَیْکُمْ وَ أَنَا حُجَّةُ اللَّهِ عَلَیْهِم» 
"When the matter arises, refer to those who narrate our ahadith, for they are my proof over you, and we are the proof of Allah over them".
It is prudent to mention that such titles can have different implications and meanings in different times and places. Naturally, there is no distinct and fixed meaning for these terms as they can be used to imply different meanings. What is important is knowledge and piety in regardst to every scholar, not the title he uses.
When it comes to the history and background of these terms and how they were used in the past, some people have narrated a history as follows:
In the fourth century, the title 'Theqat ul-islam" was used for Muhammad bin Ya'qub Kulayani since he was accepted and known to all Muslim sects. Shiites and Sunnis were referring to him as a religious authority. That was why he was called 'Theqat ul-islam'.
In fifth century, the title 'Hujjat ul-islam' was used for Imam Muhammad Ghazzali.
In the seventh century, the title 'Mohaqiq' (lit. researcher) was used for Ja'far bin Hasan Hilli, the author of Sharaye' al-Islam fi Masail al-Halal wa al-Haram.
In the eighth century, the titles 'Allamah' and 'Ayatollah" were used for Hasan bin Yusuf Hilli.
For centuries, these titles were used for specific people but in the fourth century A.H. these titles were also used for a number of other scholars and jurisprudents and they began to gain widespread use. That is to say, until the fourth century, only Allamah Hilli was used to be called 'Ayatollah'.
In the beginning the fourteenth Islamic century, Sayyid Mahdi Bahrul Ulum was called and addressed for the first time as Ayatollah. A few decades later, Sheikh Murtaza Ansari and Sayyid Muhammad Hasan Shirazi were also entitled as Ayatollah.
The historians during the "Constitutional Period" in Iran used the term 'Ayatollah' to refer Akhund Mulla Kazem Khurasani and a few other scholars. Before this period, all the religious authorities were called "Hujjat ul-islam".
Following the establishment of the Islamic Seminary of Qom by Sheikh Abdul Karim Haeri, a number of great scholars who had come together from various parts of the Shiite world were called as 'Ayatollah'. With the passage of time, some of them were then called 'Grand Ayatollah'. 
 Saheb bin Ibad, Al-Mohit fi al-Loghah, vol.10, p. 472, Beirut, Alam al-Kitab, first edition, 1414 A.H.
 Al-Dhariyat, 20 -21.
 Sheikh Saduq, Kamal al-Deen wa Tamam al-Ne'mah, researched and edited by Ghaffari, Ali Akbar, vol.2, p. 484, Tehran, Dar al-Kotob al-Islamiyah, second edition, 1395 A.H.
source : www.islamquest.net