There are really only a few tricks to solving problems like this, and the same ones come up over and over again. However, the only way to really get them into your head is to solve a few problems, so this answer won't actually solve the homework assignment in the OP. I hope it provides some ideas.
Context-free languages can be composed from other context free languages, and it doesn't really require much thought to see how to write the composition once you know what the composition is. In the following examples, I don't distinguish between non-terminals and context-free languages, because a non-terminal actually defines a context-free language. For example, if L1 and L2 are two CFGs, with productions
L1 → …
L2 → …
then the union L = L1∪ L2 is simply:
L → L1
L → L2
L1 → …
L2 → …
while the concatenation language M = L1L2 is:
M → L1 L2
L1 → …
L2 → …
Now, here are a couple of useful compositions. First, parenthetic balancing. Context-free languages can't count, except that they can count up and then count down. So (n[m]m)n is a context-free language, and it's easy to see that it can be composed by starting with
L1 = [m]m
and then defining
L2 = (nL1)n
using the following simple productions:
L1 → ε
L1 → ( L1 )
L2 → L1
L2 → [ L1 ]
I could have used a, b, c and d instead of the parentheses and brackets, but I think the intent is a bit clearer when you use parentheses.
So that's how to do equality counts. What about inequality? Let's start with a very simple language: the Kleene +. a+ is "one or more as", and the language is straightforward:
L → a
L → L a
Now consider {anbm | n ≠ m}. We can rewrite that as a union:
{anbm | n>m} ∪ {anbm | m>n}
since if m≠n then exactly one of m>n and n>m must be true.
Now look at {anbm | n>m}. Since n is strictly greater than m, we can rewrite anbm as am-nambm. But we don't really care what n-m is, just that it's at least one. So we can use the Kleene + to make am-nambm and that is obviously:
L1 → a
L1 → L1 a
L2 → ε
L2 → a L2 b
L → L1 L2
The m>n case is very similar, and to get m≠n we just need to find the union of those two languages.
I hope all that was clear.
It's common to provide puzzles like this with odd little algebraic identities. To solve them, you just need to reduce the formulas to the small number of cases shown above, using decompositions like ai+j = aiaj, which is not exactly rocket science.
For example, another SO question asked about the language {anbmc2n+m | n,m > 0}.
Solving it is simple. First, we want to parenthetically match bm, so we need to rewrite c2n+m as cmc2n. That leaves us parenthetically matching an with c2n; to make the two repetition counts the same, we need to change c2n to ccn.
Having rewritten the original as anbmcmccn, it becomes clear that the language is:
L1 → ε
L1 → b L1 c
L2 → L1
L2 → a L1 cc
which is essentially identical to the parenthetic balancing example way at the top of this answer.