Section 40D. Nothing in this section shall affect or impair local ordinances or by-laws requiring a permit to be obtained before excavation in a public way or on private property; but notwithstanding any general or special law, ordinance or by-law to the contrary, to the extent that any permit issued under the provisions of the state building code or state fire code requires excavation by an excavator on a public way or on private property, the permit shall not be valid unless the excavator notifies the system as required pursuant to sections 40 and 40A, before the commencement of the excavation, and has complied with the permitting requirements of chapter 82A.