Are these methods safe for keeping butter and margarine?
Short answer - no
Long answer - butter is a dairy product which has a high concentration of fat. It is difficult to heat fat evenly (hot spots in pastries heated in a microwave is one example). Safely preserving food at home is dependent on heating food thoroughly and evenly. And since we can't be certain of heating fat evenly it is not a food we can home process.
Alternative: Freeze it! If it is in quarters, freeze as it. Double bag in freezer safe bags to avoid any moisture loss. Or cut into squares/pats, freeze single layer and then bag when frozen -instant individual servings