SQL queries with AND/OR conditions
Have a look how orConditionGroup() is used in core.
For example, in ConfigEntityQueryTest it is used this way:

$query = $this-&gt;factory-&gt;get('config_query_test', 'AND');
$and_condition_1 = $query-&gt;orConditionGroup()
  -&gt;condition('id', '2')
  -&gt;condition('label', $this-&gt;entities[0]-&gt;label);
$and_condition_2 = $query-&gt;orConditionGroup()
  -&gt;condition('id', 1)
  -&gt;condition('label', $this-&gt;entities[3]-&gt;label);
$this-&gt;queryResults = $query
  -&gt;condition($and_condition_1)
  -&gt;condition($and_condition_2)
  -&gt;execute();


I am sure you can apply this to your problem.