When did the idea of a "race" originate?
It depends on what you mean by "race". The problem with defining race is that our ideas of the various races have changed over the course of centuries. I guess some ancient civilizations had some sort of proto racial theories, I know the Egyptians had a text that claimed there were essentially four "ethnic groups", if they could be called ethnic groups, but it's not something those of us in 2014 would really relate to when thinking about "race".
The modern concept of race can trace it's roots back to a man named Carl Linnaeus, who lived in the 1700s. In the year 1740, he wrote a book called "Systema Naturae", it was edited over the years, and by the 10th edition the book stated there were four races, Homo europaeus, Homo afer, Homo americanus, and Homo asiaticus.
Linnaeus thought that each races behaved a certain way, for example he thought Africans were negligent while Native Americans were free spirited.
People over the years would add, and remove racial categories, a man named George Cuvier said there were 3 races, Caucasian, Mongolian, and Negro. With Negros being the most "savage" and barbaric. Johann Friedrich Blumenbach in 1770 would add a new race called "Malayan", to describe the people in South East Asia. Eventually, we ended up with the racial categories we have today
How
These theories started to pop up in the 1700s, during the age of colonialism. In this time, Europeans were for the first time having regular contact with other races. The physical differences and behavioural differences between the different race and cultures became very interesting to the Europeans. Also, the Europeans wanted to know why the other races were "inferior", eventually they came up with "biological determinism" which essentially states than your mental and moral qualities are related to your physical qualities.
Then, would it be proper to say that the idea of a race became mainstream only during the colonial period , and this idea was used to describe who was 'superior' and who was 'inferior'