The peaceful quote was given when he described his pilgrimage to Mecca, and the attitude toward all (American) white people as devils is from an earlier time when he was part of the Nation of Islam.
In a 1963 interview with Louis Lomax he says:
MALCOLM X: Yes, sir, that is what The Honorable Elijah Muhammad teaches us. The white devil’s time is up; it has been up for almost fifty years now.
LOMAX: I have heard you say that a thousand times, but it always jolts me. Why do you call the white man a devil?
MALCOLM X: Because that’s what he is. What do you want me to call him, a saint? Anybody who rapes, and plunders, and enslaves, and steals, and drops hell bombs on people… anybody who does these things is nothing but a devil.
Look, Lomax, history rewards all research. And history fails to record one single instance in which the white man –as a people–did good. They have always been devils; they always will be devils, and they are about to be destroyed. The final proof that they are devils lies in the fact that they are about to destroy themselves. Only a devil–and a stupid devil at that–would destroy himself!
The full anti-racist quote is:
In the past, yes, I have made sweeping indictments of all white people. I will never be guilty of that again — as I know now that some white people are truly sincere, that some truly are capable of being brotherly toward a black man. The true Islam has shown me that a blanket indictment of all white people is as wrong as when whites make blanket indictments against blacks.
According to wikiquote is was said when he returned from the Hajj on which he departed on April 22nd, 1964. It's sourced to Malcolm X: The Seeker of Justice (2003) and Malcolm X - An Islamic Perspective.
Malcolm X - An Islamic Perspective puts its sources as
[A]dapted from the pamphlet Malcolm X: Why I Embraced Islam by Yusuf Siddiqui. Quotes taken from The Autobiography of Malcolm X as told to Alex Haley.
It also mentions that:
For twelve years [Malcolm X] preached that the white man was the devil and the "Honorable Elijah Muhammad" was God's messenger [...] although the transformation he was about to undergo would give him a completely different, and more important, message for the American people.