Origin of the Pan-Arab Colours
Red :
The Khawarij were the first Islamic group to emerge after the assassination of Caliph Othman III, forming the first republican party in the early days of Islam. Their symbol was the red flag. Arab tribes who participated in the conquest of North Africa and Andalusia carried the red flag, which became the symbol of the Islamic rulers of Andalusia (756-1355).
In modern times, red symbolizes the Ashrafs [ie. Sharifians] of the Hejaz and the Hashemites, descendants of the Prophet.
Green: The Fatimid Dynasty (909-1171), North Africa
The Fatimid Dynasty was founded in Morocco by Abdullah Al-Mahdi, and went on rule all of North Africa. They took green as their colour, to symbolize their allegiance to Ali, the Prophet's cousin, who was once wrapped in a green coverlet in place of the Prophet in order to thwart an assassination attempt.
White: The Umayyad Dynasty (661-750), Damascus
The Umayyads ruled for ninety years, taking white as their symbolic colour as a reminder of the Prophet's first battle at Badr, and to distinguish themselves from the Abbasids, by using white, rather than black, as their colour of mourning. Mu'awia Ibn Abi Sufian (661-750), founder of the Umayyad state, proclaimed himself Caliph of Jerusalem.
Black: The Prophet Mohammad (570-632)
In the seventh century, with the rise of Islam and subsequent liberation of Mecca, two flags - one white, one black - were carried. On the white flag was written, "There is no god but God (Allah) and Mohammad is the Prophet of God."
In pre-Islamic times, the black flag was a sign of revenge. It was the colour of the headdress worn when leading troops into battle. Both black and white flags were placed in the mosque during Friday prayers.
The Abbasid Dynasty (750-1258), ruling from Baghdad, took black as a symbol of mourning for the assassination of relatives of the Prophet and in remembrance of the Battle of Karbala.
(Source: Evolution of the Arab Flag, by Mahdi Abdul Hadi, Amman, February 1986)
The colours of the Iranian flag are traditional, probably dating from at least the 18th century and they can be interpreted as representing the Islamic religion (green), peace (white), and courage (red). The were first designed in tricolour form in 1907. The flag's centrepiece formerly comprised a lion with a sword standing before a rising sun, with a crown above, but all traditional flags and banners were abolished after the abdication of the shah in 1979. Note that this flag is flown "right to left" ie with the flagpole on the right.