Ohhh, I think I got it. Here is the script. Not best solution I sure, but it works.
You just need to select the face that will look up at zero rotation. Then just execute the script and it will convert rotations)
import bpy
import bmesh
from mathutils import Vector, Matrix
import logging
context = bpy.context
ob = context.edit_object
me = ob.data
bm = bmesh.from_edit_mesh(me)
face = bm.select_history.active
o = face.calc_center_median()
face.normal_update()
norm = face.normal
edges = sorted((e for e in face.edges), key=lambda e: abs((e.verts[1].co - e.verts[0].co).dot(face.normal)))
e = edges[0]
if this value is 0 then edge and normal orthogonal should test
print((e.verts[1].co - e.verts[0].co).dot(face.normal))
T = Matrix.Translation(-o)
up = Vector((0, 0, 1))
R = face.normal.rotation_difference(up).to_matrix()
R_inv = R.inverted().to_4x4()
loc = ob.location.copy()
bmesh.ops.transform(bm, verts=bm.verts, matrix=R, space=T)
forward = Vector((0, 1, 0))
R = (e.verts[1].co - e.verts[0].co).rotation_difference(forward).to_matrix()
#bmesh.ops.transform(bm, verts=bm.verts, matrix=R, space=T)
T = Matrix.Translation(face.calc_center_median() - o)
bmesh.ops.transform(bm, verts=bm.verts, matrix=T)
bmesh.update_edit_mesh(me)
bpy.ops.object.editmode_toggle()
bpy.ops.object.origin_set(type='GEOMETRY_ORIGIN', center='MEDIAN')
ob.matrix_world = R_inv
ob.location = loc