It's well known that setting bone roll to Z-axis up in blender often doesn't work well, if at all. If you find yourself having to set bone roll manually using Ctrl+R then this script might help you out. Tab into bone edit mode, select the bones you want to roll, copy and paste the below script to a text editor, set your target roll vector as new_z_axis_vector in the script below (at the moment its set for z up) and hit run script.
for each_bone in bpy.context.selected_bones:
Of course the correct rigging practice is to make sure the bone roll of all the bones in a chain is such that the z axes vectors of all the bones are in the same plane so you might want to set new_z_axis_vector to something other than (0,0,1) or world z, for example a leg IK chain might need a value of (0,1,0) to make all the bone z-axes point forward.