While I prefer butter for cookies (better flavor and texture), you certainly can use margarine!  I would recommend using the stick margarine and not the kind that comes in a tub.