Key verses:
 
Job's self-righteousness:
 
"Let God weigh me (Job) in honest scales and he will know that I am blameless" [Job:31:6]
 
God, through Elihu, rebukes Job:
 
Job 36:1 Elihu continued: 2 "Bear with me a little longer and I will show you that there is more to be said in God's behalf...
Job's problem:
 
Job 32:1 Then these three men ceased answering Job, because he was righteous in his own eyes. 2 But the anger of Elihu the son of Barachel the Buzite, of the family of Ram burned; against Job his anger burned because he justified himself before God.
Job repents:
 
Job 40:3 Then Job answered the LORD, and said , 4 "Behold, I am vile..." Job 42:6 "Wherefore I abhor myself, and repent in dust and ashes"...
 
Job's wealth is restored:
 
Job 42:12 "The LORD blessed the latter part of Job's life more than the first."
 
Conclusion:
 
When God said that Job was blameless, He was presenting Job's view of himself.