1. It's no use worrying about it.

2. It's no use to worry about it.

3. It's of no use worrying about it.

4. It's of no use to worry about it.
---------------------
Which ones are grammatical? What does 'it' in the front refer to in each sentence?

All are correct, but I wouldn't use this phrasing.

I'd change the beginning of each sentence to "There's no use worrying ... "

All four sentences are grammatically correct, but they have slight differences in meaning and usage.

1. "It's no use worrying about it."
In this sentence, "it" is an unspecified object or situation that is not worth the worry or effort. The phrase "no use" suggests that the action of worrying does not serve any practical purpose or yield any beneficial result.

2. "It's no use to worry about it."
This sentence has the same meaning as the previous one, but it includes the infinitive verb "to worry." Both the infinitive form "to worry" and the gerund form "worrying" are commonly used in this expression, so this sentence is still grammatically correct. The use of "no use" and "to worry" convey the message that the action of worrying will not be helpful or productive.

3. "It's of no use worrying about it."
In this sentence, "of" has been added before "no use." This change doesn't significantly alter the meaning; it simply emphasizes the notion that worrying has no purpose or usefulness. "It" is still an unspecified object or situation that is the subject of the statement.

4. "It's of no use to worry about it."
This sentence combines both the addition of "of" and the inclusion of the infinitive verb "to worry." Similarly to sentence 3, the addition of "of" emphasizes the lack of usefulness in worrying. "To worry about it" maintains the same meaning as in sentence 2, indicating that the action of worrying is futile.

In summary, while all four sentences are grammatically correct, they have small nuances in meaning and phrasing. The main commonality between them is the idea that worrying about the unspecified subject or situation is not useful or productive.