Why did God come down so hard on Job? There is a video/workbook series on prayer by Phillip Yancey  (which I highly recommend) (and based on one of his books) that talks about how we should pray openly about all things.
It even says that we should tell God when we are frustrated with God himself.  After all, (a) God wants to be part of our lives, (b) God already knows what we're going through and (c) if we reach out to him, he may answer our prayers or comfort us to reaffirm that he is our God.
All very valid and very useful points.
To illustrate this, he uses the illustration from Habakkuk.  In chapter 1, Habakkuk prays to God:

Habakkuk 1:2 (NIV)
How long, LORD, must I call for help,
but you do not listen?
Or cry out to you, “Violence!”
but you do not save?

God seems to respond favorably to this prayer:

Habakkuk 1:5 (NIV)
Look at the nations and watch—
and be utterly amazed.
For I am going to do something in your days
that you would not believe,
even if you were told.

There's another example of this type of prayer (praying a complaint about God) in Jeremiah 12.

However, if we look at the book of Job, we see God respond unfavorably to Job's complaining.  Job goes on for 37 chapters to complain while his friends chide him for brining it on himself (when really, as we see in Job 1, God allowed Satan to do this to Job unprovoked).
Finally, in Job 38, God answers:

Job 38:1-3 (NIV)
1 Then the LORD spoke to Job out of the storm. He said:
2 “Who is this that obscures my plans
with words without knowledge?
3 Brace yourself like a man;
I will question you,
and you shall answer me.

God goes on for four more chapters to rebuke Job to show how powerless and foolish Job is.
My question (finally):
How can we reconcile God's angry response to Job's complaining with God's favorable response to Habakkuk and Jeremiah's complaining?  What did Job do that was so wrong to bring on God's anger (in his response)?
Furthermore, how should we pray to avoid committing the sin that Job committed (in order to avoid God's wrath)?  I'm seeking the Protestant viewpoint, excluding the doctrine of reciting prayers.  This is more a question regarding open-ended prayer.  (see doctrine of prayer)
I believe it is because Job's complaining went beyond merely complaining and went into self-justification and questioning God.

Job 40:1-5


  Then the LORD said to Job,
  "Will the faultfinder contend with the Almighty? 
  Let him who reproves God answer it.
  
  Then Job answered the LORD and said,
  
  "Behold, I am insignificant; what can I reply to You? 
  I lay my hand on my mouth. 
  "Once I have spoken, and I will not answer; 
  Even twice, and I will add nothing more."


and verse 8:


  Will you really annul My judgment? 
  Will you condemn Me that you may be justified?"


and finally, Job's confession of his own wrong-doing in his over-complaining:


  Then Job answered the LORD and said,
  "I know that You can do all things, 
  And that no purpose of Yours can be thwarted. 
  'Who is this that hides counsel without knowledge?'
  Therefore I have declared that which I did not understand, 
  Things too wonderful for me, which I did not know."
  'Hear, now, and I will speak; 
  I will ask You, and You instruct me.'
  "I have heard of You by the hearing of the ear; 
  But now my eye sees You; 
  Therefore I retract, 
  And I repent in dust and ashes."


God is also angry at Job's "friends" (sidebar - with friends like those, who needs enemies?). And yes, God does say Job has spoken rightly about him as well - but there's some point beyond the right speaking that Job exceeded, too - as I understand it.