I do not believe the courts have spoken on the applicability of state or local statutes on idling locomotives regarding interstate commerce (at least I could not find case law on it). The courts have ruled on statutes concerning other matters utilizing the following criteria;
49 U.S.C. § 20106. National uniformity of regulation
Laws, regulations, and orders related to railroad safety and laws, regulations, and orders related to railroad security shall be nationally uniform to the extent practicable. A State may adopt or continue in force a law, regulation, or order related to railroad safety or security until the Secretary of Transportation (with respect to railroad safety matters), or the Secretary of Homeland Security (with respect to railroad security matters), prescribes a regulation or issues an order covering the subject matter of the State requirement. A State may adopt or continue in force an additional or more stringent law, regulation, or order related to railroad safety or security when the law, regulation, or order—
(1) is necessary to eliminate or reduce an essentially local safety or security hazard;
(2) is not incompatible with a law, regulation, or order of the United States Government; and
(3) does not unreasonably burden interstate commerce.
It would appear an anti-idling law would probably be upheld if it were enacted as a matter of security rather than to stop a nuisance, in other words the state or municipality were concerned about unattended power sitting in yards with hazardous material cars, etc. The commerce clause does not offer any entity a blanket protection against all rules and regulations on a sub-federal level. As a matter of course the Massachusetts statute on idling locomotives is part of the environmental code intended to reduce emissions.