If I'm in a threatened square can I take a 5-foot step back (to an non-threatened square) and perform a standard action like a ranged attack or cast a spell?
That is precisely how the 5-foot step rules work.
Watch Out Though
Step Up and its sequel feats are designed to counter this tactic; you may end up facing this down.
Can't remember if Pathfinder works the same, but in 3.5 you can use a standard action to perform a move action. But you can't 5 foot step in a turn in which you make a move.
So yes, you can 5 foot step and shoot/cast but you can't take a 5 foot step and then perform ANY standard action, such as 5 foot step and then 2 x 30 ft movements.