When the word gringo is used by an local towards me it is always in an warm and kidding manner, never insulting.
The deeper meaning of the word comes from many origins, some having to do with the US Mexican wars of the latter part of the 1840's. It was a war of many interpretations of political, social, and cutural situations, ie: the Attempt of the North to prevent the French from getting a foothold in Mexico, Protestant North Americans against the Catholic Mexicans, and just plain ol land grabbing. Many of the North Americans had green uniforms and it is alleged the Mexican pueblo (the simple people) would address the invaders in a manner saying "green go", meaning you don't belong here, go back home. It is also a time when the US Army had many Irish Catholic immigrants in the lower ranks. Some of the Irish fed up with their poor treatment by the Protestant officers broke rank and sided with the Mexicans who rewarded them. This was the one of the elements of forming the famous St. Patrick's Battalion, a group of Irish deserters fighting along side the Mexicans.
There is a wealth of history out there.
Regards,
PJT