It starts from the filing date of the I-485. But to safely take advantage of AC21, the I-140 should be approved before you change jobs. It doesn't matter when the I-140 was filed or approved, as long as it's been approved. The 180 days only applies to the I-485.