DateTime format (string dataFormat) or format(string dataFormat, string timezone) methods can be used in Apex. It accepts a dataFormat string, which corresponds to a Java simple date format. You will need to define the correct format for ISO 8601.
Do take into account the timezone of the DateTime. In the below example, I have used the GMT format to avoid the timezone offset.
System.debug(datetime.now().formatGMT('yyyy-MM-dd\'T\'HH:mm:ss.SSS\'Z\''));
Alternatively, you can use the JSON serializer.
System.debug(json.serialize(datetime.now()));
To learn in-depth about Workflow in Salesforce, sign up for an industry based Salesforce Admin certification.