You can do both, but mind it, the sentences have completely opposite meanings. -- As well as consequences :)
A) "It's healthier to substitute salad for pizza."
B) "It's healthier to substitute pizza with salad."
You substitute the new item for the old, but substitute the old item with the new.
When in doubt, one way to get it right without getting mired in grammar obscure details is to think of clearcut examples, and only then apply the pattern to more complex concepts.
Both the sentences above are grammatically correct. But observe that in B the order of the items is reversed, and the item discarded (pizza) shows up before the item acquired (salad).
The reason people get confused is that the verb to replace, which has a similar meaning, takes the prepositions with instead of for.
Replace (in the sense of substitute) has two main usage patterns:
"She replaced the old book shelf with a new kindle."
"The new kindle replaced the old book shelf."
The preposition by is used when the second pattern is put into passive voice:
"The old book shelf was replaced by a kindle."
So, are there any replacements in your new year resolutions list?
Writing is a good way to keep them fresh in mind and brush up your English prepositions at the same time!