you can use the OP_RETURN opcode to create an invalid transaction, & put ~40 bytes of arbitrary data into the scriptPubKey of a transaction output.
a transaction that has an OP_RETURN output is not invalid, that particular output is not spendable (for obvious reasons) that is why the amount of it is set to zero otherwise you would be burning coins.
as for the size the 40 byte is a very old rule, nowadays the limit is 83 bytes.