At least 40,000 lead and galvanized metal pipes in Erie and Niagara counties will need to be removed and replaced by 2037 under new federal drinking water rules that took effect in November.