In general, yes, you can replace a lighter weight fitting with a heavier schedule fitting.
You can replace a light weight (thinner wall) pipe like Sch40 with its heavier-walled same-dia Sch80, same material for most welded fittings - butt weld prep's need to be addressed as mentioned above.
BUT! Flanges are different: You can generally use a heavier-walled pipe within a pipeline or a pipe run (make sure you update the as-built configuration record appropriately for that section) if the specified flanges mounted outside the pipe remain the same. You CANNOT arbitrarily replace lower-rated flanges with heavier-rated (higher-rated) flanges since the bolt holes, gaskets, bolt lengths and diameters, and flange faces will then differ.