A magnetar engine for short GRBs and kilonovae