I can't find a reasonable formula for this. I know CF is used for unsigned arithmetic and OF for signed.
Please give some example arithmetic operations (like 5-7,7-5 etc.) along with the heuristic.
The answer to this question contains C code to emulate the ADD, ADC, SUB and SBB instructions with the carry and overflow flags and a test.
Another possibly interesting related question is here.
And you should be able to find this info in the official CPU documentation from Intel and AMD.